繁体   English   中英

Cucumber-JVM蚂蚁任务

[英]Cucumber-JVM ant task

我如何告诉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>

用法:java cucumber.cli.Main [options] [[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"/>更改为您要运行的目录。 请注意,您可以指定多个单独的文件和目录以空格分隔。

我也遇到了同样的问题并通过声明顶级包名来解决,就像在你的情况下包名是“cucumber.examples.java.helloworld”只是声明只有这样的黄瓜

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

在你的蚂蚁任务。 它在我身边工作。

您可以编写自己的构建文件,而不是使用随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测试<test name="com.example.YourTestClass" haltonfailure="no" outfile="result" > 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 / test / features中的所有功能文件将在执行构建文件时运行

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM