通过build.gradle传递标签,而不是通过RunCukesSpec

SMP*_*MPH 2 intellij-idea cucumber junit4 gradle

当我以下列方式传递标签时,它完美地工作.

package features

import org.junit.runner.RunWith
import cucumber.junit.Cucumber
import geb.junit4.GebReportingTest

@RunWith(Cucumber.class)
@Cucumber.Options(format = ["pretty", "html:build/cucumber", "json-pretty:build/cucumber-report.json"])
                            ,tags = ["@login_neg"])

class RunCukesSpec extends GebReportingTest {}
Run Code Online (Sandbox Code Playgroud)

但我的目标是通过build.gradle&配置相同的东西,如果它成功,然后通过命令行.我尝试在下面作为初始步骤,并希望通过gradle test在命令行中运行来获得预期的结果.

test {
    testLogging.showStandardStreams = true

    args = ['--tags', '@login_neg',
            '--format', 'html:build/cucumber',
            '--format', 'json-pretty:build/cucumber-report.json',
            '--format', 'pretty']

}
Run Code Online (Sandbox Code Playgroud)

在这种情况下,所有标签都在运行.

试过这个.但没有运气 gradle test -DCucumber.Options="--tags @login_neg"

版本:

------------------------------------------------------------
Gradle 1.9
------------------------------------------------------------

Build time:   2013-11-19 08:20:02 UTC
Build number: none
Revision:     7970ec3503b4f5767ee1c1c69f8b4186c4763e3d

Groovy:       1.8.6
Ant:          Apache Ant(TM) version 1.9.2 compiled on July 8 2013
Ivy:          2.2.0
JVM:          1.7.0_45 (Oracle Corporation 24.45-b08)
OS:           Windows 7 6.1 amd64
Run Code Online (Sandbox Code Playgroud)

小智 5

您可以通过以下方式更新build.gradle文件来将选项作为系统属性传递:

test {
  systemProperty "cucumber.options", System.properties.getProperty("cucumber.options")
}
Run Code Online (Sandbox Code Playgroud)

此配置将cucumber.optionsSystem属性从Gradle JVM传递到运行测试的JVM.

然后,您可以运行gradle test -Dcucumber.options="--help"以查看该System属性的可用选项(替换--help为您的选项).