Concordion-verifyrows

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

一致-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 verifyRows Output