Cucumber-JUnit 使用标签控制并行测试
最近,我使用 Cucumber-JUnit 创建了一个框架,我可以在其中并行执行场景(目前每个功能保留一个场景),没有任何问题。
现在我遇到的情况是某些功能必须并行运行,有些功能必须按顺序运行。
我们是否可以通过标签或任何其他配置进行控制来选择哪些必须并行或顺序运行?
让我概述一下它目前是如何
并行的,以及根据 Cucumber 官方文档控制其线程大小 - Maven Surefire
pom.xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<parallel>methods</parallel>
<threadCount>${threadSize}</threadCount>
<perCoreThreadCount>false</perCoreThreadCount>
</configuration>
</plugin>
CucumberRunner:
@RunWith(Cucumber.class)
@CucumberOptions(
features = {"src/test/resources/features"},
glue = {"com.tests.binding.steps"},
tags = "@regression"
)
public class RunCucumberFeatures {
}
命令用于运行测试
mvn clean test -Dcucumber.filter.tags="${toExecute} and not (@smoke)" -DthreadCount=${ThreadSize} -Dcucumber.execution.dry-run="false"
>toExecute
参数 - 我们传递多个标签,例如 @customerClaim 或 @employeeClaim
现在,在我的例子中,具有标签 @employeeClaim应并行执行,带有 @customerClaim 的标签应按顺序执行。
目前的设计或其他方式是否可行?
Recently I created a framework with Cucumber-JUnit where I am able to execute Scenarios in parallel (For now keeping one scenario per feature) without any issue.
Now I have a situation where some of the features has to run in parallel and some in sequence.
Is there any way that we can control with tags or any other configuration to choose which has to run in parallel or sequence?
Let me put some overview how it is currently
Parallel and its thread size controlled as per cucumber official documentation - Maven surefire
pom.xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<parallel>methods</parallel>
<threadCount>${threadSize}</threadCount>
<perCoreThreadCount>false</perCoreThreadCount>
</configuration>
</plugin>
CucumberRunner:
@RunWith(Cucumber.class)
@CucumberOptions(
features = {"src/test/resources/features"},
glue = {"com.tests.binding.steps"},
tags = "@regression"
)
public class RunCucumberFeatures {
}
command using to run tests
mvn clean test -Dcucumber.filter.tags="${toExecute} and not (@smoke)" -DthreadCount=${ThreadSize} -Dcucumber.execution.dry-run="false"
For toExecute
parameter - we pass multiple tags like @customerClaim or @employeeClaim
Now, In my case features with tags @employeeClaim should execute in parallel and tags with @customerClaim should execute in sequence.
Is it possible with current design or any other way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
cucumber-junit
和 JUnit 4 则不然。但是,使用 JUnit 5,您可以使用cucumber-junit-platform-engine
并使用 JUnit 5s 对独占资源的支持。https://github.com/cucumber/cucumber-jvm/树/主/junit-platform-engine
因此,通过为
@customerClaim
创建独占资源,您可以防止这些场景并行运行。然而,据我所知,JUnit 5 不保证执行顺序,因此它们仍然应该彼此独立。Not with
cucumber-junit
and JUnit 4. However with JUnit 5 you can use thecucumber-junit-platform-engine
and use JUnit 5s support for exclusive resources.https://github.com/cucumber/cucumber-jvm/tree/main/junit-platform-engine
So by making an exclusive resource for
@customerClaim
you can prevent these scenarios from running in parallel. However to the best of my knowledge JUnit 5 makes no guarantees made about the order of execution so they should still be independent from each other.如果我们可以仅通过标签选择并行运行哪些测试,那就太好了。我很快就会与微服务作斗争,我希望我的大部分测试能够并行运行以节省时间。到目前为止,我一直在测试一个整体,并且我的框架已经完成了多个 .feature 文件和配置为在不同环境上运行的标签。因此,如果有一种简单的方法来配置哪些测试并行运行,其余的测试使用标签按顺序运行——那么很高兴知道。
It would be nice if we could select which tests to run in parallel only by tags. I will be fighting with microservices very soon and I would like most of my tests to run in parallel to save time. So far I have been testing a monolith and my framework is already done with multiple .feature files and tags configured to run on different environments. So if there is an easy way to configure which tests to run in parallel and the rest in sequence using tags - it would be nice to know.