Concordion-set-command
提供:Dev Guides
一致-setコマンド
Concordion setコマンドは、他のConcordionコマンドで使用できる一時変数を保存するために使用されます。
次の要件を考慮してください-
The Sum of two numbers 2 and 3 will be 5.
数値2と3をパラメーターとして使用し、それらをシステムから返された結果と照合できるようにパラメーターとしてsum関数に渡す場合、数値の周囲のspanタグ内でconcordion:setコマンドを使用できます。
<p>The Sum of two numbers <span concordion:set = "#firstNumber">2</span>
and <span concordion:set = "#secondNumber">3</span> will be
<span concordion:assertEquals = "sum(#firstNumber, #secondNumber)">5
</span>.</p>
Concordionはドキュメントを解析するときに、一時変数#firstNumberを値 "2"に設定し、#secondNumberを値 "3"に設定してから、#firstNumberおよび#secondNumberとしてパラメーターを指定してsum()メソッドを呼び出し、結果は「5」に等しくなります。
例
動作するEclipse IDEを用意し、以下の手順に従ってConcordionアプリケーションを作成します-
Step | Description |
---|---|
1 | Create a project with a name concordion and create a package com.finddevguides under the src folder in the created project. |
2 | Add the required Concordion libraries using Add External JARs option as explained in the Concordion - First Application chapter. |
3 | Create Java class System under the com.finddevguides package. |
4 | Create Fixture class SystemFixture under the specs.finddevguides package. |
5 | Create Specification html Systeml under the specs.finddevguides package. |
6 | The final step is to create the content of all the Java files and specificiation file and run the application as explained below. |
System.javaファイルの内容は次のとおりです-
package com.finddevguides;
public class System {
public int sum(int firstNumber, int secondNumber) {
return firstNumber + secondNumber;
}
}
SystemFixture.javaファイルの内容は次のとおりです-
package specs.finddevguides;
import org.concordion.integration.junit4.ConcordionRunner;
import org.junit.runner.RunWith;
import com.finddevguides.System;
@RunWith(ConcordionRunner.class)
public class SystemFixture {
System system = new System();
public int sum(int firstNumber, int secondNumber) {
return system.sum(firstNumber, secondNumber);
}
}
以下はSystemlファイルの内容です-
<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>
<p>The Sum of two numbers <span concordion:set = "#firstNumber">2</span>
and <span concordion:set = "#secondNumber">3</span> will be
<span concordion:execute = "#result = sum(#firstNumber, #secondNumber)"></span>
<span concordion:assertEquals = "#result">5</span>.</p>
</div>
</body>
</html>
ソースファイルと仕様ファイルの作成が完了したら、アプリケーションをJUnitテストとして実行します。 すべてがあなたのアプリケーションでうまくいけば、それは次の結果を生成します-
C:\DOCUME>1\ADMINI>1\LOCALS>1\Temp\concordion\specs\finddevguides\Systeml
Successes: 1, Failures: 0
Systemlは、コンコーディオンテスト実行の出力です。