使用System.getProperty()获取@CucumberOptions标记属性

Cha*_*man 14 java eclipse properties test-runner cucumber-jvm

我正在Eclipse中运行一个maven项目来进行我的Cucumber测试.我的测试运行器类看起来像这样:

@RunWith(Cucumber.class)
@CucumberOptions(
        tags = { "@Now" },      
//      tags = { "@Ready" },
//      tags = { "@Draft" },
        features = { "src/test/java/com/myCompany/FaultReporting/Features" },
        glue = { "com.myCompany.myApp.StepDefinitions" }
        )
public class RunnerTest {   
}
Run Code Online (Sandbox Code Playgroud)

我不想将标签硬编码到测试运行器中,而是希望使用.command文件传递它们.(即使用System.getProperty("cucumber.tag")

但是,当我将代码行添加到上面的测试运行器时,我收到错误:

@RunWith(Cucumber.class)
@CucumberOptions(
        tags = { System.getProperty("cucumber.tag") }
//      tags = { "@Now" },      
//      tags = { "@Ready" },
//      tags = { "@Draft" },
        features = { "src/test/java/com/myCompany/FaultReporting/Features" },
        glue = { "com.myCompany.myApp.StepDefinitions" }
        )
public class RunnerTest {   
}
Run Code Online (Sandbox Code Playgroud)

我得到的错误是:"注释属性CucumberOptions.tags的值必须是常量表达式".

所以它似乎只需要常量而不是参数化值.任何人都知道这个聪明的方式吗?

Rei*_*eus 17

您可以使用cucumber.options环境变量在运行时指定标记

mvn -D"cucumber.options=--tags @Other,@Now" test
Run Code Online (Sandbox Code Playgroud)

这取代了测试代码中已包含的标签.