Concordion-quick-guide
コンコード-概要
コンコードとは何ですか?
Concordionは、Javaベースのプロジェクトで自動化された受け入れテストを作成および管理するための強力なツールです。 JUnitフレームワークと直接統合されるため、Netbeans、Eclipse、IntelliJ IDEAなどのすべての一般的なJavaベースのIDEですぐに使用できます。
アクティブなソフトウェア仕様
アクティブなソフトウェア仕様は、機能の動作を指定する方法です。 また、開発中のシステムと接続することにより、ソフトウェア仕様を実装および検証する方法も提供します。
Concordionのアクティブな仕様は2つの部分からなります-
- XHTMLを使用して記述された目的の機能を説明する、明確に記述された要件ドキュメント。 XHTMLベースの仕様には、受け入れテストの例で提供される機能の説明が含まれています。 例のデータは、単純なHTMLタグを使用してマークされます。
- 受け入れテストは、フィクスチャコードと呼ばれるJava言語で記述されています。 標準のJUnitテストケースのConcordion拡張機能を使用して、テストが実装されます。 タグでマークされたサンプルのデータを見つけ、それらを使用して開発中のソフトウェアを検証するのは、フィクスチャコードの責任です。
一致の出力
Concordionのアクティブな仕様テストを実行すると、出力XHTMLファイルには元の仕様とテスト結果が表示されます。 成功したテストは「緑」の色で強調表示され、失敗したテストは「赤」で強調表示されます。 システムに変更があると、テストに失敗し、仕様が常に最新であることを保証します。 一致は、これらの仕様をアクティブな仕様と見なします。
主な機能
以下は、Concordionの主要な機能です-
- ドキュメントとしての仕様-読みやすいコンコーディオン仕様は、アクティブなシステムドキュメントとして使用できます。 Concordionベースの仕様はHTMLで記述されているため、これらのドキュメントはハイパーリンクできます。
- 仕様はライブ-コンコーディオン仕様には、システムに対して実行される動作の動作例が含まれています。 仕様は色分けされているため、例が機能しているかどうかを誰でも確認できます。 Concordionの仕様を定期的に実行すると、ドキュメントが最新になります。
- *個別の「何?」 from "how?" *-コンコーディオンの仕様は、システムの実装と必要な動作を分離するのに役立ちます。 後で実装を変更する柔軟性を提供します。
- 学習が簡単-コンコードライブラリは非常に簡潔です。 学習するコマンドはほとんどなく、JUnitテストを使用してサンプルが自動化されているため、テストを簡単に実行でき、既存のプロジェクトと簡単に統合できます。
- 強力なカスタマイズ-Concordionは、機能を追加できる拡張機能APIを提供します。 たとえば、Excelスプレッドシートを仕様として使用したり、スクリーンショットを出力に追加したり、ログ情報を表示したりできます。
一致-環境
ここでは、Concordionを利用するための開発環境を準備する方法について説明します。 Concordionを使用する前に、システムにJDK、Tomcat、およびEclipseをセットアップする必要があります。 ステップバイステップで行きましょう。
ステップ1-Java Development Kit(JDK)のセットアップ
JDKの最新バージョンは、OracleのJavaサイト(http://www.oracle.com/technetwork/java/javase/downloads/indexl[Java SE Downloads])からダウンロードできます。 ダウンロードしたファイルにJDKをインストールする手順が記載されています。 指定された指示に従って、セットアップをインストールおよび構成します。 最後に、PATHおよびJAVA_HOME環境変数を設定して、javaおよびjavacを含むディレクトリ(通常はそれぞれjava_install_dir/binおよびjava_install_dir)を参照します。
Windowsを実行していて、C:\ jdk1.7.0_75にJDKをインストールした場合、C:\ autoexec.batファイルに次の行を追加する必要があります。
set PATH=C:\jdk1.7.0_75\bin;%PATH%
set JAVA_HOME=C:\jdk1.7.0_75
または、Windows NT/2000/XPでは、マイコンピュータを右クリックして、[プロパティ]、[詳細設定]、[環境変数]の順に選択することもできます。 次に、PATH値を更新し、[OK]ボタンを押します。
Unix(Solaris、Linuxなど)では、SDKが/usr/local/jdk1.7.0_75にインストールされており、Cシェルを使用する場合、次を.cshrcファイルに追加します。
setenv PATH/usr/local/jdk1.7.0_75/bin:$PATH
setenv JAVA_HOME/usr/local/jdk1.7.0_75
あるいは、Borland JBuilder、Eclipse、IntelliJ IDEA、またはSun ONE Studioなどの統合開発環境(IDE)を使用している場合は、単純なプログラムをコンパイルおよび実行して、IDEがJavaのインストール先を認識していることを確認します。 IDEのドキュメントに記載されています。
ステップ2-Eclipse IDEのセットアップ
このチュートリアルのすべての例は、Eclipse IDEを使用して作成されています。 そのため、最新バージョンのEclipseをシステムにインストールすることをお勧めします。
Eclipse IDEをインストールするには、http://www.eclipse.org/downloads/から最新のEclipseバイナリをダウンロードします。 インストールをダウンロードした後、バイナリ配布物を便利な場所に解凍します。 たとえば、WindowsのC:\ eclipse、またはLinux/Unixの/usr/local/eclipseで、最後にPATH変数を適切に設定します。
Eclipseは、Windows環境で次のコマンドを実行することで開始できます。または、eclipse.exeをダブルクリックするだけです
%C:\eclipse\eclipse.exe
Eclipseは、Unix(Solaris、Linuxなど)マシンで次のコマンドを実行することで開始できます-
$/usr/local/eclipse/eclipse
正常に起動した後、すべてが正常であれば、次の結果が表示されます-
ステップ3:Junitアーカイブをダウンロードする
http://www.junit.orgからJUnit jarファイルの最新バージョンをダウンロードします。 このチュートリアルを書いている時点で、_Junit-4.10.jar_をダウンロードし、C:\> JUnitフォルダーにコピーしました。
OS | Archive name |
---|---|
Windows | junit4.10.jar |
Linux | junit4.10.jar |
Mac | junit4.10.jar |
ステップ4:JUnit環境を設定する
*JUNIT_HOME* 環境変数を設定して、マシン上のJUnit jarが保存されているベースディレクトリの場所を指すようにします。 JUNITフォルダーにjunit4.10.jarを保存したと仮定します。次に、作業しているOSに応じて次のいずれかのアクションを実行する必要があります-
OS | Action |
---|---|
Windows | Set the environment variable JUNIT_HOME to C:\JUNIT |
Linux | export JUNIT_HOME=/usr/local/JUNIT |
Mac | export JUNIT_HOME=/Library/JUNIT |
ステップ5:CLASSPATH変数を設定する
JUNIT jarの場所を指すようにCLASSPATH環境変数を設定します。 JUNITフォルダーにjunit4.10.jarを保存したと仮定します。次に、作業しているOSに基づいて次のいずれかのアクションを実行する必要があります-
OS | Action |
---|---|
Windows | Set the environment variable CLASSPATH to %CLASSPATH%;%JUNIT_HOME%\junit4.10.jar;.; |
Linux | export CLASSPATH=$CLASSPATH:$JUNIT_HOME/junit4.10.jar:. |
Mac | export CLASSPATH=$CLASSPATH:$JUNIT_HOME/junit4.10.jar:. |
手順6-Concordionライブラリのセットアップ
これで、Concordionライブラリのセットアップに進むことができます。 以下の簡単な手順に従って、フレームワークをダウンロードしてマシンにインストールします。
Concordionフレームワークバイナリの最新バージョンをhttp://concordion.org/download/java/markdown/[[[1]]]からダウンロードします。
このチュートリアルを書いている時点で、WindowsマシンにConcordion-1.5.1をダウンロードしました。 ダウンロードしたファイルを解凍すると、E:\ Concordion-1.5.1内に次のディレクトリ構造が表示されます。
- lib -ライブラリフォルダー
- hamcrest-core-1.3.jar
- junit-4.12.jar
- ognl-2.6.9.jar
- xom-1.2.5.jar
- src -ソースコードフォルダー
- main
- test
- テストダミー
- Concordion-1.5.1.jar
すべてのConcordion依存ライブラリは、ディレクトリE:\ Concordion \ libにあります。 このディレクトリでCLASSPATH変数を適切に設定してください。そうしないと、アプリケーションの実行中に問題が発生します。 Eclipseを使用している場合、すべての設定はEclipseを介して行われるため、CLASSPATHを設定する必要はありません。
この最後の手順を完了すると、次の章で説明する最初のConcordion Exampleに進む準備が整います。
一致-最初のアプリケーション
Concordionでプログラミングを始めましょう。 Concordionを使用して最初の例の記述を開始する前に、リンク:/concordion/concordion_environment [Concordion-Environment Setup]チュートリアルで説明されているように、Concordion環境を適切にセットアップしていることを確認する必要があります。 また、Eclipse IDEの実用的な知識があることも前提としています。
それでは、次の受け入れテストを印刷する簡単なConcordionアプリケーションの作成に進みましょう-
Example
When Robert logs in the system, a greeting "Hello Robert!" is displayed.
ステップ1-Javaプロジェクトの作成
最初のステップは、Eclipse IDEを使用して単純なJavaプロジェクトを作成することです。 ファイル→新規→プロジェクト*オプションに従い、最後にウィザードリストから Javaプロジェクト*ウィザードを選択します。 次のようにウィザードウィンドウを使用して、プロジェクトに Concordion という名前を付けます-
プロジェクトが正常に作成されると、 Project Explorer に次のコンテンツが表示されます-
ステップ2-必要なライブラリを追加する
プロジェクトに一致とその依存関係を追加しましょう。 これを行うには、プロジェクト名 concordion を右クリックし、コンテキストメニューで使用可能なオプションに従います。*ビルドパス→ビルドパスの設定*のように、Javaビルドパスウィンドウを表示します-
[ライブラリ]タブにある[外部JARの追加]ボタンを使用して、Concordionフォルダーから次のコアJARを追加します。
- concordion-1.5.1
- hamcrest-core-1.3
- junit-4.12
- ognl-2.6.9
- xom-1.2.5
手順3-ソースファイルの作成
*concordion* プロジェクトの下に実際のソースファイルを作成しましょう。 まず、 *com.finddevguides* というパッケージを作成する必要があります。 これを行うには、パッケージエクスプローラーセクションで *src* を右クリックし、オプション:*新規→パッケージ*に従います。
次に、com.finddevguidesパッケージの下にSystem .java ファイルを作成します。
*System.java* ファイルの内容は次のとおりです-
package com.finddevguides;
public class System {
public String getGreeting(String userName){
return "Hello " + userName + "!";
}
}
ステップ4-仕様ファイルの作成
*concordion* プロジェクトの下に実際の仕様ファイルを作成しましょう。 まず、 *specs* という名前の新しいソースフォルダーを作成する必要があります。 このフォルダーには、JUnitFixtureやテストランナーなどの仕様ファイルと、仕様であるhtmlファイルが含まれます。 次に、 *specs.finddevguides* というパッケージを作成する必要があります。 これを行うには、パッケージエクスプローラーセクションで *spec* を右クリックし、オプション *New→Package* に従います。
次に、specs.finddevguidesパッケージの下に Systeml および SystemFixture.java ファイルを作成します。 その後、specsソースフォルダに concordion.css を追加します。
これが Systeml ファイルの内容です-
<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 show greeting to logged in user:</p>
<div class = "example">
<h3>Example</h3>
<p>When <span concordion:set = "#userName">Robert</span>
logs in the system, a greeting "<span concordion:assertEquals = "getGreeting(#userName)">
Hello Robert!</span>" is displayed.</p>
</div>
</body>
</html>
*SystemFixture.java* ファイルの内容は次のとおりです-
package specs.finddevguides;
import com.finddevguides.System;
import org.concordion.integration.junit4.ConcordionRunner;
import org.junit.runner.RunWith;
@RunWith(ConcordionRunner.class)
public class SystemFixture {
System system = new System();
public String getGreeting(String userName){
return system.getGreeting(userName);
}
}
ここに concordion.css ファイルの内容があります-
*{
font-family: Arial;
}
body {
padding: 32px;
}
pre {
padding: 6px 28px 6px 28px;
background-color: #E8EEF7;
}
pre, pre* , code, code *, kbd {
font-family: Courier New, Courier;
font-size: 10pt;
}
h1, h1 *{
font-size: 24pt;
}
p, td, th, li, .breadcrumbs {
font-size: 10pt;
}
p, li {
line-height: 140%;
}
table {
border-collapse: collapse;
empty-cells: show;
margin: 8px 0px 8px 0px;
}
th, td {
border: 1px solid black;
padding: 3px;
}
td {
background-color: white;
vertical-align: top;
}
th {
background-color: #C3D9FF;
}
li {
margin-top: 6px;
margin-bottom: 6px;
}
.example {
padding: 6px 16px 6px 16px;
border: 1px solid #D7D7D7;
margin: 6px 0px 28px 0px;
background-color: #F7F7F7;
}
.example h3 {
margin-top: 8px;
margin-bottom: 8px;
font-size: 12pt;
}
.special {
font-style: italic;
}
.idea {
font-size: 9pt;
color: #888;
font-style: italic;
}
.tight li {
margin-top: 1px;
margin-bottom: 1px;
}
.commentary {
float: right;
width: 200px;
background-color: #ffffd0;
padding:8px;
border: 3px solid #eeeeb0;
margin: 10px 0px 10px 10px;
}
.commentary, .commentary* {
font-size: 8pt;
}
仕様のhtmlファイルとテストフィクスチャについて注意すべき2つの重要な点があります-
- Systemlは、コンコーディオン名前空間を使用する仕様htmlファイルです。
<html xmlns:concordion="http://www.concordion.org/2007/concordion">
- Systemlはconcordion:setコマンドを使用して、一時変数userNameの値をRobertに設定します。 ここで、userNameはSystemフィクスチャのgetGreetingメソッドに渡されるパラメーターです。
When <span concordion:set="#userName">Robert</span> logs in the system
- Systemlは、concordion:assertEqualsコマンドを使用して、getGreeting(userName)関数の出力がHello Robert!であることを確認します。
a greeting "<span concordion:assertEquals="getGreeting(#userName)">
Hello Robert!</span>" is displayed.
- SystemFixtureは、ConcordionRunner.classアノテーションが付けられたJUnitテストフィクスチャです。
@RunWith(ConcordionRunner.class)
public class SystemFixture {}
- SystemFixtureには、ユーザーに挨拶を返すgetGreetingメソッドがあります。
public String getGreeting(String userName){
return system.getGreeting(userName);
}
ステップ5-プログラムの実行
SystemFixtureのコンテンツ領域を右クリックして、[として実行]> [* JUnitテストケース*]を選択します。 次の出力が表示され、junitが成功します。
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\concordion\specs\finddevguides\Systeml
Successes: 1, Failures: 0
システムは、Concordionテスト実行の出力です。
おめでとうございます。最初のConcordion Acceptanceテストが正常に作成されました。 さらに、次のいくつかの章でもっと面白いことを始めましょう。
一致-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は、コンコーディオンテスト実行の出力です。
一致-assertEqualsコマンド
Concordion assertEqualsコマンドを使用して、指定した値に対してJava Beanのプロパティまたはメソッドの結果を確認します。
次の要件を考慮してください-
The sum of two numbers 2 and 3 will be 5.
数値2と3をパラメーターとして使用し、それらをシステムとして返された結果5に対して検証できるようにパラメーターとして合計関数に渡す場合、合計関数の周囲のspanタグ内でconcordion:assertEqualsコマンドを使用できます。
<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がドキュメントを解析するとき、setコマンドを使用して一時変数#firstNumberを値 "2"に設定し、#secondNumberを値 "3"に設定し、#firstNumberおよび#secondNumberとしてパラメーターを指定してsum()メソッドを呼び出します。 assertEqualsコマンドを使用して、結果が「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 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:assertEquals = "sum(#firstNumber, #secondNumber)">5</span>.</p>
</div>
</body>
</html>
ソースファイルと仕様ファイルの作成が完了したら、アプリケーションをJUnitテストとして実行します。 すべてがあなたのアプリケーションでうまくいけば、それは次の結果を示します-
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\concordion\specs\finddevguides\Systeml
Successes: 1, Failures: 0
システムは、Concordionテスト実行の出力です。
Concordion assertEqualsコマンドの出力
成功:1、失敗:0
一致-assertTrueコマンド
Concordion assertTrueコマンドは、テストを実行するためにフィクスチャーが期待される結果を知る必要がある場合に使用されます。
次の要件を考慮してください-
User Name : Robert De
The User name starts with R.
The User name starts with S == false.
ユーザー名でテストを実行し、ユーザー名がRで始まるかどうかを確認する場合。
<p>User Name :<span concordion:set = "#userName">Robert De</span></p>
<p>The User name <span concordion:assertTrue = "#userName.startsWith(#letter)">starts
with <b concordion:set = "#letter">R</b></span>.</p>
<p>The User name <span concordion:assertTrue = "#userName.startsWith(#letter)">starts
with <b concordion:set = "#letter">S</b></span>.</p>
Concordionがドキュメントを解析するとき、一時変数#userNameを値「Robert De」に設定します。 次に、userNameが次のコマンドで設定された#letter変数で指定された文字で始まるかどうかを確認します。
例
動作する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 specification file and run the application as explained below. |
System.javaファイルの内容は次のとおりです-
package com.finddevguides;
public class System {
}
SystemFixture.javaファイルの内容は次のとおりです-
package specs.finddevguides;
import org.concordion.integration.junit4.ConcordionRunner;
import org.junit.runner.RunWith;
@RunWith(ConcordionRunner.class)
public class SystemFixture {
}
以下は、Systemlファイルの内容です-
<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>
<p>User Name :<span concordion:set = "#userName">Robert De</span></p>
<p>The User name <span concordion:assertTrue = "#userName.startsWith(#letter)">starts
with <b concordion:set = "#letter">R</b></span>.</p>
<p>The User name <span concordion:assertTrue = "#userName.startsWith(#letter)">starts
with <b concordion:set = "#letter">S</b></span>.</p>
</div>
</body>
</html>
ソースファイルと仕様ファイルの作成が完了したら、アプリケーションをJUnitテストとして実行します。 すべてがあなたのアプリケーションでうまくいけば、それは次の結果を生成します-
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\concordion\specs\finddevguides\Systeml
Successes: 1, Failures: 1
システムは、Concordionテスト実行の出力です。
一致-assertFalseコマンド
Concordion assertFalseコマンドは、テストを実行するためにフィクスチャーが期待される結果を知る必要がある場合に使用されます。
次の要件を考慮してください-
User Name : Robert De
The User name does not start with S.
ユーザー名でテストを実行し、ユーザー名がSで始まっていないことを確認する場合
<p>User Name :<span concordion:set = "#userName">Robert De</span></p>
<p>The User name <span concordion:assertFalse = "#userName.startsWith(#letter)">does not start
with <b concordion:set = "#letter">S</b></span>.</p>
Concordionがドキュメントを解析するとき、一時変数#userNameを値「Robert De」に設定します。 次に、userNameが次のコマンドで設定された#letter変数で指定された文字で始まるかどうかを確認します。
例
動作する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 specification file and run the application as explained below. |
System.javaファイルの内容は次のとおりです-
package com.finddevguides;
public class System {
}
SystemFixture.javaファイルの内容は次のとおりです-
package specs.finddevguides;
import org.concordion.integration.junit4.ConcordionRunner;
import org.junit.runner.RunWith;
@RunWith(ConcordionRunner.class)
public class SystemFixture {
}
以下は、Systemlファイルの内容です-
<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>
<p>User Name :<span concordion:set = "#userName">Robert De</span></p>
<p>The User name <span concordion:assertFalse = "#userName.startsWith(#letter)">
does not start with <b concordion:set = "#letter">
S</b></span>.</p>
</div>
</body>
</html>
ソースファイルと仕様ファイルの作成が完了したら、アプリケーションをJUnitテストとして実行します。 すべてがあなたのアプリケーションでうまくいけば、それは次の結果を生成します-
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\concordion\specs\finddevguides\Systeml
Successes: 1, Failures: 0
システムは、Concordionテスト実行の出力です。
一致-コマンドの実行
一致実行コマンドは、一致フィクスチャの操作を実行するために使用されます。 次の要件を考慮してください-
The sum of two numbers 2 and 3 will be 5.
私たちは2つの数字を受け入れ、その合計を出力する合計関数の仕様を書きたい場合、仕様は次のようになります-
<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>
Concordionはドキュメントを解析するときに、一時変数#firstNumberを値 "2"に設定し、#secondNumberを値 "3"に設定してから、executeを使用して#firstNumberおよび#secondNumberのようなパラメーターでsum()メソッドを実行しますコマンドを実行し、結果を#result変数に設定し、#result変数が「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 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 specification 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
システムは、Concordionテスト実行の出力です。
一致-オブジェクトを返す
Concordion executeコマンドを使用すると、ビヘイビアの複数の出力を取得できるオブジェクトの形でビヘイビアの結果を取得できます。 たとえば、次の要件を考慮してください-
The full name Robert De is to be broken into first name Robert and last name De.
ここでは、ユーザー名を受け入れ、プロパティとして名と姓を使用する結果オブジェクトを返す分割関数を用意する必要があります。
私たちは、ユーザー名を期待し、結果オブジェクトを出力するような分割関数の仕様を書きたい場合は、次の仕様になります-
<p>The full name <span concordion:execute = "#result = split(#TEXT)">Robert
De</span> is to be broken into first name
<span concordion:assertEquals = "#result.firstName">Robert</span> and last name
<span concordion:assertEquals = "#result.lastName">De</span>.</p>
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.finddevguides 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.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 specification file and run the application as explained below. |
ここにResult.javaファイルの内容があります-
package com.finddevguides;
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.finddevguides;
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.finddevguides;
import com.finddevguides.Result;
import com.finddevguides.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);
}
}
以下はSystemlファイルの内容です-
<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>
<p>The full name <span concordion:execute = "#result = split(#TEXT)">Robert
De</span> is to be broken into first name <span
concordion:assertEquals = "#result.firstName">Robert</span> and last name <span
concordion:assertEquals = "#result.lastName">De</span>.</p>
</div>
</body>
</html>
ソースファイルと仕様ファイルの作成が完了したら、JUnitテストとしてアプリケーションを実行します。 すべてがあなたのアプリケーションでうまくいけば、それは次の結果を生成します-
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\concordion\specs\finddevguides\Systeml
Successes: 1, Failures: 0
システムは、Concordionテスト実行の出力です。
一致-マップを返す
Concordion executeコマンドを使用して、ビヘイビアの結果をMapの形式で取得できます。これを使用して、ビヘイビアの複数の出力を取得できます。 たとえば、次の要件を考慮してください-
The full name Robert De is to be broken into its first name Robert and last name De.
ここでは、ユーザー名を受け入れ、firstNameとlastNameをキーとして対応する値を持つMapオブジェクトを返すスピル関数を使用して、それらを使用できるようにする必要があります。
私たちは、ユーザー名を受け入れ、結果オブジェクトを出力するような分割関数の仕様を記述したい場合、次は仕様になります-
<p>The full name <span concordion:execute = "#result = split(#TEXT)">Robert
De</span> is to be broken into first name <span
concordion:assertEquals = "#result.firstName">Robert</span> and last name <span
concordion:assertEquals = "#result.lastName">De</span>.</p>
Concordionがドキュメントを解析するとき、特別な変数#TEXTの値を「Robert De」として現在の要素の値に設定し、それをsplit関数に渡します。 次に、executeコマンドを使用して#TEXTとしてパラメーターを指定してsplit()メソッドを実行し、結果を#result変数に設定し、結果マップを使用して、firstNameおよびlastNameの値を出力として出力します。
例
動作する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 specification file and run the application as explained below. |
System.javaファイルの内容は次のとおりです-
package com.finddevguides;
import java.util.HashMap;
import java.util.Map;
public class System {
public Map split(String userName){
Map<String, String> result = new HashMap<String, String>();
String[] words = userName.split(" ");
result.put("firstName", words[0]);
result.put("lastName", words[1]);
return result;
}
}
SystemFixture.javaファイルの内容は次のとおりです-
package specs.finddevguides;
import java.util.Map;
import com.finddevguides.Result;
import com.finddevguides.System;
import org.concordion.integration.junit4.ConcordionRunner;
import org.junit.runner.RunWith;
@RunWith(ConcordionRunner.class)
public class SystemFixture {
System system = new System();
public Map<String, String> split(String userName){
return system.split(userName);
}
}
以下はSystemlファイルの内容です-
<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>
<p>The full name <span concordion:execute = "#result = split(#TEXT)">Robert
De</span> is to be broken into first name <span
concordion:assertEquals = "#result.firstName">Robert</span> and last name
<span concordion:assertEquals = "#result.lastName">De</span>.</p>
</div>
</body>
</html>
ソースファイルと仕様ファイルの作成が完了したら、JUnitテストとしてアプリケーションを実行します。 すべてがあなたのアプリケーションでうまくいけば、それは次の結果を生成します-
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\concordion\specs\finddevguides\Systeml
Successes: 1, Failures: 0
システムは、Concordionテスト実行の出力です。
一致-MultiValueResultを返す
Concordion executeコマンドを使用して、ビヘイビアの結果をMapの形式で取得できます。これを使用して、ビヘイビアの複数の出力を取得できます。 たとえば、次の要件を考慮してください-
The full name Robert De is to be broken into its first name Robert and last name De.
ここでは、ユーザー名を受け入れ、firstNameとlastNameをキーとして対応する値を持つMapオブジェクトを返すsplit関数を使用して、それらを使用できるようにする必要があります。
ユーザー名を受け入れ、結果オブジェクトを出力するような分割関数の仕様を記述したい場合、仕様は次のようになります-
<p>The full name <span concordion:execute = "#result = split(#TEXT)">Robert
De</span> is to be broken into first name
<span concordion:assertEquals = "#result.firstName">Robert</span> and last name
<span concordion:assertEquals = "#result.lastName">De</span>.</p>
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.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 specification file and run the application as explained below. |
System.javaファイルの内容は次のとおりです-
package com.finddevguides;
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.finddevguides;
import org.concordion.api.MultiValueResult;
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 MultiValueResult split(String userName){
return system.split(userName);
}
}
以下はSystemlファイルの内容です-
<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>
<p>The full name <span concordion:execute = "#result = split(#TEXT)">Robert De</span>
is to be broken into first name <span
concordion:assertEquals = "#result.firstName">Robert</span> and last name <span
concordion:assertEquals = "#result.lastName">De</span>.</p>
</div>
</body>
</html>
ソースファイルと仕様ファイルの作成が完了したら、JUnitテストとしてアプリケーションを実行します。 すべてがあなたのアプリケーションでうまくいけば、それは次の結果を生成します-
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\concordion\specs\finddevguides\Systeml
Successes: 2, Failures: 0
システムは、Concordionテスト実行の出力です。
一致-テーブルで実行
一致実行コマンドを使用すると、一致フィクスチャの操作を繰り返し実行できます。 たとえば、テーブルの形で複数の例を使用して要件を説明する場合に役立ちます。
次の要件を考慮してください-
<table>
<tr><th>First Number</th><th>Second Number</th><th>Sum</th></tr>
<tr><td>2</td><td>3</td><td>5</td></tr>
<tr><td>4</td><td>5</td><td>9</td></tr>
</table>
私たちは2つの数字を受け入れ、その合計を出力する合計関数の仕様を書きたい場合、仕様は次のようになります-
<table>
<tr><th>First Number</th><th>Second Number</th><th>Sum</th></tr>
<tr concordion:execute = "#result = sum(#fullName)">
<td concordion:set = "#firstNumber">2</td>
<td concordion:set = "#secondNumber">3</td>
<td concordion:assertEquals = "#result">5</td>
</tr>
<tr concordion:execute = "#result = sum(#fullName)">
<td concordion:set = "#firstNumber">4</td>
<td concordion:set = "#secondNumber">5</td>
<td concordion:assertEquals = "#result">9</td>
</tr>
</table>
Concordionはドキュメントを解析するときに、一時変数#firstNumberを値「2」に設定し、#secondNumberを値「3」に設定します。 次に、executeコマンドを使用して#firstNumberおよび#secondNumberのようなパラメーターでsum()メソッドを実行し、結果を#result変数に設定し、#result変数が「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 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 specification 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>
<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\finddevguides\Systeml
Successes: 2, Failures: 0
システムは、Concordionテスト実行の出力です。
一致-リストで実行
一致実行コマンドを使用すると、一致フィクスチャの操作を繰り返し実行できます。 たとえば、リスト形式で複数の例を使用して要件を説明する場合に役立ちます。
次の要件を考慮してください-
<ul>
<li>The full name Robert De is to be split as
<ul>
<li>Robert</li>
<li>De</li>
</ul>
</li>
<li>The full name John Diere is to be split as
<ul>
<li>John</li>
<li>Diere</li>
</ul>
</li>
</ul>
名前を名と姓に分割する分割関数の仕様を記述したい場合、仕様は次のようになります-
<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>
Concordionがドキュメントを解析するとき、特別な変数#TEXTの値を「Robert De」として現在の要素の値に設定し、それをsplit関数に渡します。 次に、executeコマンドを使用して#TEXTとしてパラメーターを指定してsplit()メソッドを実行し、結果を#result変数に設定し、resultを使用して、firstNameおよびlastNameの値を出力として出力します。
例
動作する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 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 specification file and run the application as explained below. |
System.javaファイルの内容は次のとおりです-
package com.finddevguides;
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.finddevguides;
import org.concordion.api.MultiValueResult;
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 MultiValueResult split(String userName){
return system.split(userName);
}
}
以下はSystemlファイルの内容です-
<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>
</body>
</html>
ソースファイルと仕様ファイルの作成が完了したら、アプリケーションをJUnitテストとして実行します。 すべてがあなたのアプリケーションでうまくいけば、それは次の結果を生成します-
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\concordion\specs\finddevguides\Systeml
Successes: 4, Failures: 0
システムは、Concordionテスト実行の出力です。
一致-verifyRowsコマンド
Concordion verifyRowsコマンドを使用して、システムによって結果として返されるコレクションのコンテンツを確認できます。 たとえば、システムに一連のユーザーを設定し、それらを部分的に検索する場合、システムは一致する要素を返す必要があります。そうでない場合、受け入れテストは失敗します。
次の要件を考慮してください-
<table>
<tr><th>Users</th></tr>
<tr><td>Robert De</td></tr>
<tr><td>John Diere</td></tr>
<tr><td>Julie Re</td></tr>
</table>
<p>Search for J should return:</p>
<table>
<tr><th>Matching Users</th></tr>
<tr><td>John Diere</td></tr>
<tr><td>Julie Re</td></tr>
</table>
コレクションを検索して返すような検索関数の仕様を記述したい場合、仕様は次のようになります-
<table concordion:execute = "addUser(#username)">
<tr><th concordion:set = "#username">Username</th></tr>
<tr><td>Robert De</td></tr>
<tr><td>John Diere</td></tr>
<tr><td>Julie Re</td></tr>
</table>
<p>Search for "<b concordion:set = "#searchString">J</b>" should return:</p>
<table concordion:verifyRows = "#username : search(#searchString)">
<tr><th concordion:assertEquals = "#username">Matching Usernames</th></tr>
<tr><td>John Diere</td></tr>
<tr><td>Julie Re</td></tr>
</table>
Concordionがドキュメントを解析するとき、最初のテーブルの各行でaddUser()を実行し、searchStringをJに設定します。 次に、Concordionは、予測可能な反復順序でIterableオブジェクトを返す検索関数を実行します(例: List、LinkedHashSetまたはTreeSet)、verifyRowsはコレクションの各アイテムに対して実行され、assertEqualsコマンドを実行します。
例
動作する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 specification file and run the application as explained below. |
System.javaファイルの内容は次のとおりです-
package com.finddevguides;
import java.util.HashSet;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
public class System {
private Set<String> users = new HashSet<String>();
public void addUser(String username) {
users.add(username);
}
public Iterable<String> search(String searchString) {
SortedSet<String> matches = new TreeSet<String>();
for (String username : users) {
if (username.contains(searchString)) {
matches.add(username);
}
}
return matches;
}
}
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 void addUser(String username) {
system.addUser(username);
}
public Iterable<String> search(String searchString) {
return system.search(searchString);
}
}
以下はSystemlファイルの内容です-
<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 add a partial search capability on user names:</p>
<div class = "example">
<h3>Example</h3>
<table concordion:execute = "addUser(#username)">
<tr><th concordion:set = "#username">Username</th></tr>
<tr><td>Robert De</td></tr>
<tr><td>John Diere</td></tr>
<tr><td>Julie Re</td></tr>
</table>
<p>Search for "<b concordion:set = "#searchString">J</b>" should return:</p>
<table concordion:verifyRows = "#username : search(#searchString)">
<tr><th concordion:assertEquals = "#username">Matching Usernames</th></tr>
<tr><td>John Diere</td></tr>
<tr><td>Julie Re</td></tr>
</table>
</div>
</body>
</html>
ソースファイルと仕様ファイルの作成が完了したら、JUnitテストとしてアプリケーションを実行します。 すべてがあなたのアプリケーションでうまくいけば、それは次の結果を生成します-
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\concordion\specs\finddevguides\Systeml
Successes: 2, Failures: 0
システムは、Concordionテスト実行の出力です。
一致-コマンドの実行
Concordion runコマンドを使用して、複数の仕様をリンクし、それらを1つの中央ページに表示できます。 このコマンドは、必要に応じてリンクの背景を緑/赤/灰色で表示しながら、すべての仕様を実行できます。
次に、2つの仕様を作成し、それらをリンクします。 link:/concordion/concordion_execute_list [Concordion-Execute on List]およびlink:/concordion_execute_table [Concordion-Execute on Table]の章で作成された仕様を、システム仕様および電卓仕様として再利用します。
例
動作する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 classes SystemFixture, CalculatorFixture under the specs.finddevguides package. |
5 | Create Specification html files Systeml, Calculatorl under the specs.finddevguides 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. |
System.javaファイルの内容は次のとおりです-
package com.finddevguides;
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.finddevguides;
import org.concordion.api.MultiValueResult;
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 MultiValueResult split(String userName){
return system.split(userName);
}
}
以下はCalculatorFixture.javaファイルの内容です-
package specs.finddevguides;
import org.concordion.integration.junit4.ConcordionRunner;
import org.junit.runner.RunWith;
import com.finddevguides.System;
@RunWith(ConcordionRunner.class)
public class CalculatorFixture {
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>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 = "Calculatorl">
Calculator Service Specifications</a>
</body>
</html>
以下はCalculatorlファイルの内容です-
<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\finddevguides\Systeml
Successes: 2, Failures: 0
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\concordion\specs\finddevguides\Systeml
Successes: 6, Failures: 0
システムは、Concordionテスト実行の出力です。
[Calculator Service Specifications]リンクをクリックします。 次の出力が表示されます-