从可执行 JAR 运行单个黄瓜场景

cfh*_*yes 4 cucumber-jvm cucumber-junit cucumber-java cucumber-serenity

我想将我的验收测试打包到一个可执行 JAR 中,其中包含运行测试和生成报告所需的所有库。我还想运行所有测试或单个测试。

到目前为止,我能够运行所有测试,尽管在我在 serenity.properties 中指定的位置生成报告,但没有生成 index.html。

通常,我会使用 maven verify 目标运行我的测试,该目标将运行 serenity-maven-plugin,但由于我是从 JAR 运行的,我不确定如何实现相同的目标。

我有一个主类,如下所示:

@RunWith(CucumberWithSerenity.class)
@CucumberOptions(features = "classpath:com/cfhayes/test/LookupADefinition.feature")
public class DefinitionTestSuite {
  public static void main(String[] args) throws Exception {
    JUnitCore.main("com.cfhayes.test.DefinitionTestSuite");
  }
}
Run Code Online (Sandbox Code Playgroud)

我的功能文件使用标签,以便我可以指定要运行的单个场景:

Feature: Lookup a definition

  @TEST-0001
  Scenario: Looking up the definition of 'apple'
    Given the user is on the Wikionary home page
    When the user looks up the definition of the word 'apple'
    Then they should see the definition 'A common, round fruit produced by the tree Malus domestica, cultivated in temperate climates.'

  @TEST-0002
  Scenario: Looking up the definition of 'pear'
    Given the user is on the Wikionary home page
    When the user looks up the definition of the word 'pear'
    Then they should see the definition 'An edible fruit produced by the pear tree, similar to an apple but elongated towards the stem.'
Run Code Online (Sandbox Code Playgroud)

我希望有一种方法可以将 JVM args 与可执行 JAR 一起使用,以某种方式允许我设置黄瓜选项。我尝试做这样的事情:

java -jar my-test-jar.jar -Dcucumber.options="--tags @TEST-0001" 
Run Code Online (Sandbox Code Playgroud)

...但这仍然运行所有测试。

任何想法将不胜感激。

Myk*_*rov 5

您构造命令的方式可能不正确。Cucumber 选项被作为参数com.cfhayes.test.DefinitionTestSuite::main而不是 java 选项。尝试这个:

java -Dcucumber.options="--tags @TEST-0001" -jar my-test-jar.jar
Run Code Online (Sandbox Code Playgroud)

或者在你的班级中处理黄瓜选项。