Concordion - 在列表上执行


Concordion执行命令可用于重复运行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>

如果我们想为 split 函数编写一个规范,它将一个名字分割成名字和姓氏,那么规范将如下 -

<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 应用程序 -

描述
1 创建一个名为concordion的项目,并在创建的项目中的src文件夹下创建一个包com.tutorialspoint 。
2 使用添加外部 JAR选项添加所需的 Concordion 库,如Concordion - 第一个应用程序章节中所述。
3 com.tutorialspoint包下创建Java类System
4 specs.tutorialspoint包下创建Fixture类SystemFixture
5 specs.tutorialspoint包下创建规范html System.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;
   }
}

以下是 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);
   }  
}

以下是 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>
   </body>

</html>

创建完源文件和规范文件后,让我们将应用程序作为 JUnit 测试运行。如果您的应用程序一切正常,那么它将产生以下结果 -

C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\concordion\specs\tutorialspoint\System.html
Successes: 4, Failures: 0

System.html 是 Concordion 测试运行的输出。

concordion 在列表输出上执行