使用System.getProperty()获取@CucumberOptions标签属性 [英] Get @CucumberOptions tag property using System.getProperty()
问题描述
@RunWith(Cucumber.class)
@CucumberOptions(
标签= {@Now},
// tags = {@Ready},
// tags = {@Draft},
features = {src / test / java / com / myCompany / FaultReporting / Features},
glue = {com.myCompany.myApp.StepDefinitions}
)
public class RunnerTest {
}
我不想将代码硬编码到测试运行器中,我很想传递他们使用。命令文件。 (即使用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 {
}
我得到的错误是:
注释属性CucumberOptions.tags必须是一个常量表达式。
所以似乎只需要常量,而不是一个参数化的值。 >
您可以使用 cucumber.options
环境变量来指定运行时
mvn -Dcucumber.options = - 标签@其他,@ Nowtest
这取代了测试代码中已经包含的标签。
I am running a maven project in Eclipse for my Cucumber tests. My test runner class looks like this:
@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 {
}
Instead of having to hard code the tags into the test runner, I am keen to pass them in using the .command file. (i.e. using System.getProperty("cucumber.tag")
However, I get an error when I add the line of code to the above test runner:
@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 {
}
The error I get is: "The value for annotation attribute CucumberOptions.tags must be a constant expression".
So seems it only wants constants rather than a parameterised value. Anyone know a clever way round this?
You can use the cucumber.options
environmental variable to specify the tags at runtime
mvn -D"cucumber.options=--tags @Other,@Now" test
This supercedes the tags already contained in the test code.
这篇关于使用System.getProperty()获取@CucumberOptions标签属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!