简体   繁体   English

Cucumber 如何使用不同的被测代码多次运行功能?

[英]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.

相关问题 如何运行多个黄瓜功能? - How to run multiple cucumber features? 如何使用为Cucumber JVM中的每个新运行设置的不同数据(语言)多次运行相同的功能文件 - How to run the same feature file multiple times with different data (language) set for every new run in Cucumber JVM 如何针对不同的值多次运行测试方法 - how to run test method multiple times for different values 如何在黄瓜中不使用大纲的情况下多次运行同一场景? - How to run same scenario multiple times without using outline in Cucumber? 如何多次使用相同的测试数据多次运行同一JUnit测试? - How do I run the same JUnit test multiple times with different test data each time? 使用不同的参数多次运行一个 junit 测试 - Run one junit test multiple times with different parameters 使用不同的参数使jUnitRunner运行测试类多次 - Make jUnit runner run test class multiple times with different parameters 在JUnit 4中使用不同的@BeforeClass设置多次运行测试用例 - Run a test case multiple times with different @BeforeClass setups in JUnit 4 如何使用不同的WebDriver配置多次运行junit测试套件 - How tu run junit test suite multiple times with different WebDriver configuration 如何在 Gradle 中通过命令行使用不同的系统属性多次运行测试? - How to run test multiple times with different system property via command line in Gradle?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM