2012-07-13 111 views
3

我該如何告訴ant在一個文件夾中執行所有的黃瓜測試(功能,實現)?Cucumber-JVM ant任務

我堅持用這個例子

<target name="runcukes" depends="compile-test"> 
     <mkdir dir="target/cucumber-junit-report"/> 
     <java classname="cucumber.cli.Main" fork="true" failonerror="false" resultproperty="cucumber.exitstatus"> 
      <classpath refid="classpath"/> 
      <arg value="--format"/> 
      <arg value="junit:target/cucumber-junit-report/allcukes.xml"/> 
      <arg value="--format"/> 
      <arg value="pretty"/> 
      <arg value="--format"/> 
      <arg value="html:target/cucumber-html-report"/> 
      <arg value="--glue"/> 
      <arg value="cucumber.examples.java.helloworld"/> 
      <arg value="src/test/resources"/> 
     </java> 

     <junitreport todir="target/cucumber-junit-report"> 
      <fileset dir="target/cucumber-junit-report"> 
       <include name="allcukes.xml"/> 
      </fileset> 
      <report format="frames" todir="target/cucumber-junit-report"/> 
     </junitreport> 

     <fail message="Cucumber failed"> 
      <condition> 
       <not> 
        <equals arg1="${cucumber.exitstatus}" arg2="0"/> 
       </not> 
      </condition> 
     </fail> 
    </target> 

回答

6

用法:java的cucumber.cli.Main [選項] [[FILE | DIR] [:LINE [:LINE] *] +

選項:

-g, --glue PATH Where glue code (step definitions and hooks) is loaded from. 
-f, --format FORMAT[:OUT] How to format results. Goes to STDOUT unless OUT is specified. 
           Available formats: junit, html, pretty, progress, json, json-pretty. 
-t, --tags TAG_EXPRESSION Only run scenarios tagged with tags matching TAG_EXPRESSION. 
-n, --name REGEXP Only run scenarios whose names match REGEXP. 
-d, --dry-run Skip execution of glue code. 
-m, --monochrome Don't colour terminal output. 
    --dotcucumber Where to write out runtime information. 
-v, --version Print version. 
-h, --help You're looking at it. 

在你的情況 - 改變<arg value="src/test/resources"/>您要針對其運行目錄。請注意,您可以指定多個以空格分隔的單個文件和目錄。

0

代替使用隨github中的示例一起提供的構建文件,您可以編寫自己的構建文件。

嘗試使用ant的Junit任務從ant運行Junit測試文件。將「@ Cucumber.Options」註釋的「格式」設置爲指向具有您的要素的目錄。

要運行JUnit測試,下面的目標添加到您的構建文件,

<junit printsummary="yes" failureproperty="junit.failure"> 

<classpath refid="id_of_the_path_to_find_JARS/.class files"></classpath> 

<test name="com.example.YourTestClass" haltonfailure="no" outfile="result" > 
<formatter type="plain"/> 
<formatter type="xml"/> 
</test> 

</junit> 

<test name="com.example.YourTestClass" haltonfailure="no" outfile="result" >指定的Juint測試將被執行。該YourTestClass.java將這個樣子......

import cucumber.api.junit.Cucumber; 
import org.junit.runner.RunWith; 

@RunWith(Cucumber.class) 

@Cucumber.Options(format = {"html:target/cucumber-html","junit:target/cucumber-junit/Webpage.xml"},features = "src/test/features") 
public class YourTestClass { 

} 

所有功能的文件保存在的src /測試/功能在執行構建文件將運行

1

我也面臨同樣的問題,通過聲明頂部的包名你區分包名是像解決「cucumber.examples.java.helloworld」就在你的Ant任務聲明僅黃瓜這樣

<arg value="--glue"/> 
<arg value="cucumber"/> 

。它在我身上工作結束。