[英]Cucumber how to run features multiple times with different code under test?
The shot version: How do I do Junit's @RunWith(Parameterized::class)
with cucumber features?拍摄版本:如何使用 cucumber 功能执行 Junit 的
@RunWith(Parameterized::class)
?
I have feature files that I like.我有我喜欢的功能文件。 I want to run the exact same features multiple times, but change "the environment" so the
@Before
code in my step-defs is slightly different.我想多次运行完全相同的功能,但更改“环境”,因此我的 step-defs 中的
@Before
代码略有不同。 I have a few different implementations of some code under test, and I want to make sure they all work.我对一些正在测试的代码有几种不同的实现,我想确保它们都能正常工作。 So it has to be part of the CI pipeline.
所以它必须是 CI 管道的一部分。 Not a manual cmd-line thing
不是手动命令行的东西
The thing I want to change between runs has no semantic meaning to the scenarios/features file, so I would prefer not to radically alter/duplicate them.我想在运行之间更改的东西对场景/功能文件没有语义意义,所以我不希望从根本上改变/复制它们。
I'm using stock java/kotlin and gradle junit.我正在使用股票 java/kotlin 和 gradle junit。 No spring, no webUI
没有 spring,没有 webUI
I setup multiple junit hooks all pointing to the same features, which works for running the features multiple times.我设置了多个 junit 钩子都指向相同的功能,这适用于多次运行这些功能。 But I can't figure out how to get any information from the hook to the step-defs.
但我不知道如何从钩子到 step-defs 获取任何信息。
--- update --- - - 更新 - -
Here is the code I have to plug the cucumber tests into junit:这是我必须将 cucumber 测试插入 junit 的代码:
@RunWith(Cucumber::class)
@CucumberOptions(
features = ["src/test/resources/hellocucumber/"],
)
class FirstRun
@RunWith(Cucumber::class)
@CucumberOptions(
features = ["src/test/resources/hellocucumber/"],
)
class SecondRun
This does run the tests twice, which is what I want.这确实运行了两次测试,这就是我想要的。
But in my step-defs I the @Before
section were I setup the code under test, how do I tell if it's the first run, or the second?但是在我的步骤定义中,
@Before
部分是我设置了被测代码,我如何判断它是第一次运行还是第二次运行? I can't figure out a way to get any data from these stubs to the step-defs.我想不出一种方法来从这些存根中获取任何数据到 step-defs。
Maybe this isn't the way to do this?也许这不是这样做的方法?
What about using environment variables to modify your before code, and then instead of trying to cucumber to run features multiple times, script to run cucumber multiple times each with a different environment variables.如何使用环境变量来修改您之前的代码,然后尝试使用 cucumber 多次运行功能,脚本来多次运行 cucumber,每次使用不同的环境变量。
You can either user different values for ENV vars.您可以为 ENV 变量使用不同的值。 Or even different sets of ENV vars.
甚至是不同的 ENV 变量集。
Your features will know which run they are in from ENV,您的功能将从 ENV 知道它们在哪个运行中,
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.