- Concordion 教程
- Concordion - 首页
- Concordion - 概述
- Concordion - 环境设置
- Concordion - 第一个应用
- Concordion - set 命令
- assertEquals 命令
- Concordion - assertTrue 命令
- Concordion - assertFalse 命令
- Concordion - execute 命令
- Concordion - 返回对象
- Concordion - 返回映射
- 返回多值结果
- Concordion - 在表格上执行
- Concordion - 在列表上执行
- Concordion - verifyRows 命令
- Concordion - run 命令
- Concordion 有用资源
- Concordion - 快速指南
- Concordion - 有用资源
- Concordion - 讨论
Concordion - 运行命令
Concordion run 命令可以用来链接多个规范并将其显示在一个中心页面上。此命令可以运行所有规范,同时根据需要将链接背景显示为绿色/红色/灰色。
现在我们将创建两个规范并将它们链接在一起。我们将重复使用在Concordion - 在列表上执行和Concordion - 在表格上执行章节中创建的规范作为系统规范和计算器规范。
示例
让我们准备好一个可运行的 Eclipse IDE,并按照以下步骤创建一个 Concordion 应用:
步骤 | 描述 |
---|---|
1 | 创建一个名为 concordion 的项目,并在创建的项目中的 src 文件夹下创建一个包 com.tutorialspoint。 |
2 | 如Concordion - 第一个应用章节中所述,使用添加外部 JAR 选项添加所需的 Concordion 库。 |
3 | 在 com.tutorialspoint 包下创建 Java 类 System。 |
4 | 在 specs.tutorialspoint 包下创建 Fixture 类 SystemFixture、CalculatorFixture。 |
5 | 在 specs.tutorialspoint 包下创建规范 html 文件 System.html、Calculator.html。 |
6 | 最后一步是创建所有 Java 文件和规范文件的内容,然后按如下所述运行应用程序。 |
以下是 System.java 文件的内容:
package com.tutorialspoint; 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; } public int sum(int firstNumber, int secondNumber) { return firstNumber + secondNumber; } }
以下是 SystemFixture.java 文件的内容:
package specs.tutorialspoint; import org.concordion.api.MultiValueResult; import org.concordion.integration.junit4.ConcordionRunner; import org.junit.runner.RunWith; import com.tutorialspoint.System; @RunWith(ConcordionRunner.class) public class SystemFixture { System system = new System(); public MultiValueResult split(String userName){ return system.split(userName); } }
以下是 CalculatorFixture.java 文件的内容:
package specs.tutorialspoint; import org.concordion.integration.junit4.ConcordionRunner; import org.junit.runner.RunWith; import com.tutorialspoint.System; @RunWith(ConcordionRunner.class) public class CalculatorFixture { System system = new System(); public int sum(int firstNumber, int secondNumber) { return system.sum(firstNumber, secondNumber); } }
以下是 System.html 文件的内容:
<html xmlns:concordion = "http://www.concordion.org/2007/concordion"> <head> <link href = "../concordion.css" rel = "stylesheet" type = "text/css" /> </head> <body> <h1>System Specifications</h1> <p>We are building specifications for our online order tracking application.</p> <p>Following is the requirement to split full name of a logged in user to its constituents by splitting name by whitespace:</p> <div class = "example"> <h3>Example</h3> <ul> <li>The full name <span concordion:execute = "#result = split(#TEXT)"> Robert De</span> is to be splited as <ul> <li><span concordion:assertEquals = "#result.firstName"> Robert</span></li> <li><span concordion:assertEquals = "#result.lastName"> De</span></li> </ul> </li> <li>The full name <span concordion:execute = "#result = split(#TEXT)"> John Diere</span> is to be splited as <ul> <li><span concordion:assertEquals = "#result.firstName"> John</span></li> <li><span concordion:assertEquals = "#result.lastName"> Diere</span></li> </ul> </li> </ul> </div> <a concordion:run = "concordion" href = "Calculator.html"> Calculator Service Specifications</a> </body> </html>
以下是 Calculator.html 文件的内容:
<html xmlns:concordion = "http://www.concordion.org/2007/concordion"> <head> <link href = "../concordion.css" rel = "stylesheet" type = "text/css" /> </head> <body> <h1>Calculator Specifications</h1> <p>We are building online calculator support in our website.</p> <p>Following is the requirement to add two numbers:</p> <div class = "example"> <h3>Example</h3> <table> <tr> <th>First Number</th> <th>Second Number</th> <th>Sum</th> </tr> <tr concordion:execute = "#result = sum(#firstNumber, #secondNumber)"> <td concordion:set = "#firstNumber">2</td> <td concordion:set = "#secondNumber">3</td> <td concordion:assertEquals = "#result">5</td> </tr> <tr concordion:execute = "#result = sum(#firstNumber, #secondNumber)"> <td concordion:set = "#firstNumber">4</td> <td concordion:set = "#secondNumber">5</td> <td concordion:assertEquals = "#result">9</td> </tr> </table> </div> </body> </html>
创建源文件和规范文件后,让我们将其作为 JUnit 测试运行。如果您的应用程序一切正常,则会产生以下结果:
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\concordion\specs\tutorialspoint\System.html Successes: 2, Failures: 0 C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\concordion\specs\tutorialspoint\System.html Successes: 6, Failures: 0
System.html 是 Concordion 测试运行的输出。
点击链接“计算器服务规范”。您将看到以下输出:
广告