Concordion-execute-table

提供:Dev Guides
移動先:案内検索

一致-テーブルで実行

一致実行コマンドを使用すると、一致フィクスチャの操作を繰り返し実行できます。 たとえば、テーブルの形で複数の例を使用して要件を説明する場合に役立ちます。

次の要件を考慮してください-

<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テスト実行の出力です。

concordionテーブル出力で実行