📅  最后修改于: 2020-12-07 04:43:27             🧑  作者: Mango
可以使用Concordion execute命令以对象的形式获取行为的结果,通过该对象我们可以获取行为的多个输出。例如,考虑以下要求-
The full name Robert De is to be broken into first name Robert and last name De.
在这里,我们需要一个split函数,该函数接受一个用户名并返回一个具有名字和姓氏作为其属性的结果对象,以便我们可以使用它们。
如果我们要编写这样的拆分函数的规范,该规范将期望用户名并输出结果对象,则以下将是规范-
The full name Robert
De is to be broken into first name
Robert and last name
De.
当Concordion解析文档时,它将把特殊变量#TEXT的值设置为当前元素的值“ Robert De”,并将其传递给split函数。然后,它将使用execute命令以#TEXT作为参数执行split()方法,并将结果设置为#result变量,并使用结果对象,将firstName和lastName属性打印为输出。
让我们拥有一个运行良好的Eclipse IDE,并按照下面给出的步骤创建一个Concordion应用程序-
Step | Description |
---|---|
1 | Create a project with the name concordion and create a package com.tutorialspoint under the src folder in the created project. |
2 | Add the required Concordion libraries using the Add External JARs option as explained in the Concordion – First Application chapter. |
3 | Create Java class System, Result under the com.tutorialspoint package. |
4 | Create Fixture class SystemFixture under the specs.tutorialspoint package. |
5 | Create Specification html System.html under the specs.tutorialspoint package. |
6 | The final step is to create the content of all the Java files and specification file and run the application as explained below. |
这是Result.java文件的内容-
package com.tutorialspoint;
public class Result {
private String firstName;
private String lastName;
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
}
这是System.java文件的内容-
package com.tutorialspoint;
public class System {
public Result split(String userName){
Result result = new Result();
String[] words = userName.split(" ");
result.setFirstName(words[0]);
result.setLastName(words[1]);
return result;
}
}
以下是SystemFixture.java文件的内容-
package specs.tutorialspoint;
import com.tutorialspoint.Result;
import com.tutorialspoint.System;
import org.concordion.integration.junit4.ConcordionRunner;
import org.junit.runner.RunWith;
@RunWith(ConcordionRunner.class)
public class SystemFixture {
System system = new System();
public Result split(String userName){
return system.split(userName);
}
}
以下是System.html文件的内容-
System Specifications
We are building specifications for our online order tracking application.
Following is the requirement to split full name of a logged in user to its
constituents by splitting name by whitespace:
Example
The full name Robert
De is to be broken into first name Robert and last name De.
创建完源文件和规范文件后,让我们将应用程序作为JUnit Test运行。如果您的应用程序一切正常,则将产生以下结果-
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\concordion\specs\tutorialspoint\System.html
Successes: 1, Failures: 0
System.html是Concordion测试运行的输出。