我想要一个 testNG/Cucumber 运行程序和一个 testng @Test,它允许我将单个功能文件的名称作为 testng 参数传递(使用 @Parameter)并运行它。我想要一个运行时解决方案。
我有一堆使用 TestNG 框架编写的非 Cucumber 测试,我也希望其中包含 Cucumber 代码。
有没有人想出一些聪明的办法?
最佳答案
弄清楚如何将包含功能文件名的自定义 cucumberoptions 发送到运行程序类。这将允许从 testng.xml 运行 Cucumber 和非 Cucumber 测试。
以下文本基于“Cucumber for Java”书中的详细信息...
<小时/>Cucumber 检查是否为 @CucumberOptions 注释提供了任何选项覆盖。从上到下依次检查,找到任何一个就停止:
- 操作系统环境变量 CUCUMBER_OPTIONS
- Java 系统属性 cucumber.options
- 带有 cucumber.options 属性的 Java 资源包 cucumber.properties
在 override 中找到的值将替换除插件参数之外的任何设置值。将附加插件参数。未被覆盖的参数不会受到影响。
<小时/>testng.xml
<suite name="Default suite">
<test name="Cucumber Mix">
<classes>
<class name="cucumtestng.test.RunAbstractSampleTest"></class>
<class name="cucumtestng.test.NormalTest"></class>
</classes>
</test>
</suite>
@CucumberOptions(features="",glue="cucumtestng.test.stepdefs",snippets=SnippetType.CAMELCASE,
plugin={"pretty", "html:report", "json:reports.json"})
public class RunAbstractSampleTest extends AbstractTestNGCucumberTests {
}
public class NormalTest {
@Test
public void f() {
System.out.println("NORMAL TESTNG CLASS");
}
}
您还可以使用 testng Cucumber 类,它不扩展 AbstractTestNgCucumberTests 但使用组合...
关于java - TestNG 和 cucumber : Pass in single feature file name as parameter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43480287/