Concordion execute命令可用于以重复方式运行concordion fixture的操作.例如,如果我们想以列表的形式说明具有多个示例的需求,那将非常有用.
考虑以下要求 :
- The full name Robert De is to be split as
- Robert
- De
- The full name John Diere is to be split as
- John
- Diere
如果我们想要为分割函数写一个规范,将一个名称拆分为它的名字和姓氏,那么规范将如下 :
- The full name Robert De is to be splited as
- Robert
- De
- The full name John Diere is to be splited as
- John
- Diere
当Concordion解析文档时,它会将特殊变量#TEXT的值设置为当前元素的值为"Robert De"并传递它分裂功能.然后它将使用execute命令执行带有#TEXT参数的split()方法,并将结果设置为#result变量并使用result,打印firstName和lastName值作为输出.
示例
让我们使用一个有效的Eclipse IDE,并按照下面给出的步骤创建一个Concordion应用程序 :
Step | 描述 |
---|---|
1 | 创建一个名为 concordion 的项目并创建一个包 com. it1352在创建的项目中的 src 文件夹下. |
2 | 使用添加外部JAR 选项添加所需的Concordion库,如 Concordion - First Application 章节中所述. |
3 | 在 com.IT下创建Java类系统屋包. |
4 | 在 specs.it1352包下创建Fixture类 SystemFixture . |
5 | 在下创建规范html System.html specs.it1352包. |
6 | 决赛步骤是创建所有Java文件和规范文件的内容并运行应用程序,如下所述. |
这里是System.java文件的内容 :
package com.it1352;import org.concordion.api.MultiValueResult;public class System { public MultiValueResult split(String userName){ MultiValueResult result = new MultiValueResult(); String[] words = userName.split(" "); result.with("firstName", words[0]).with("lastName", words[1]); return result; }}
以下是SystemFixture.java文件的内容 :
package specs.it1352;import org.concordion.api.MultiValueResult;import org.concordion.integration.junit4.ConcordionRunner;import org.junit.runner.RunWith;import com.it1352.System;@RunWith(ConcordionRunner.class)public class SystemFixture { System system = new System(); public MultiValueResult 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 splited as
- Robert
- De
- The full name John Diere is to be splited as
- John
- Diere
完成创建源文件和规范文件之后,让我们将应用程序作为JUnit Test运行.如果您的应用程序一切正常,那么它将产生以下结果 :
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\concordion\specs\it1352\System.htmlSuccesses: 4, Failures: 0
System.html是Concordion测试运行的输出.