How do i tell ant to execute all cucumber tests (features, implementations) in a folder?

I'm stuck using this example

<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>
有帮助吗?

解决方案

Usage: java cucumber.cli.Main [options] [ [FILE|DIR][:LINE[:LINE]*] ]+

Options:

-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.

In your case - change the <arg value="src/test/resources"/> to directory you want to run against. Note that you can specify multiple individual files and directories space-separated.

其他提示

I also faced same problem and solved by declaring top package name like in you case the package name is "cucumber.examples.java.helloworld" Just declare only cucumber like this

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

in you ant task. It's working at me end.

Instead of using the build file provided along with the samples from github, you can write your own build file.

Try running the Junit test file from ant using ant's Junit task. Set "format" of "@Cucumber.Options" annotation to point to the directory having your features.

Example

To run the Junit test,add the following target to your build file,

<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>

The Juint test specified in the <test name="com.example.YourTestClass" haltonfailure="no" outfile="result" > will be executed. The YourTestClass.java will look like this...

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 {

}

All the feature files kept in src/test/features will run while executing the build file

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top