Cucumber-JUnit控制带标记的并行测试

wmomyfyw  于 2022-11-11  发布在  其他
关注(0)|答案(2)|浏览(218)

最近,我用Cucumber-JUnit创建了一个框架,在这个框架中,我能够并行执行Scenarios(现在每个特性都有一个Scenarios),没有任何问题。
现在,我遇到了这样一种情况:一些功能必须并行运行,而另一些功能必须按顺序运行
我们是否可以通过标记或任何其他配置来选择并行运行还是顺序运行?
让我来概括一下
平行线及其螺纹尺寸根据Cucumb官方文件控制- 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>

" cucumber 赛跑“

@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 or @employeeClaim
现在,在我的例子中,带有标记
@employeeClaim的功能应该并行执行**,带有标记**@customerClaim的功能应该按顺序执行**。
用当前的设计或任何其他方式是否可行?

mm5n2pyu

mm5n2pyu1#

我们是否可以通过标记或任何其他配置来选择并行运行还是顺序运行?
cucumber-junit和JUnit 4不能使用。但是,对于JUnit 5,您可以使用cucumber-junit-platform-engine并使用JUnit 5s对独占资源的支持。
https://github.com/cucumber/cucumber-jvm/tree/main/junit-platform-engine
要同步特定资源上的方案,必须标记该方案,并将此标记Map到特定资源的锁。资源由任意字符串标识,并且可以使用读写锁或读锁锁定。
例如,以下标记:

Feature: Exclusive resources

   @reads-and-writes-system-properties
   Scenario: first example
      Given this reads and writes system properties
      When it is executed
      Then it will not be executed concurrently with the second example

   @reads-system-properties
   Scenario: second example
      Given this reads system properties
      When it is executed
      Then it will not be executed concurrently with the first example

使用此配置:

cucumber.execution.exclusive-resources.reads-and-writes-system-properties.read-write=java.lang.System.properties
cucumber.execution.exclusive-resources.reads-system-properties.read=java.lang.System.properties

当执行以@reads-and-writes-system-properties标记的第一个场景时,将java.lang.System.properties使用读写锁来锁定www.example.com资源,并且不会与使用读锁来锁定同一资源的第二个场景同时执行。
注意:标记中的@不包含在属性名称中。注意:有关规范的资源名称,请参见junit 5/Resources.java
因此,通过为@customerClaim创建一个独占资源,可以防止这些场景并行运行。但是,据我所知,JUnit 5并不保证执行顺序,因此它们仍然是相互独立的。

mkshixfv

mkshixfv2#

如果我们可以只通过标记来选择并行运行的测试,那就太好了。我很快就要和微服务打交道了,我希望我的大多数测试都能并行运行,以保存时间。到目前为止,我一直在测试一个整体,我的框架已经完成了多个.feature文件和标记,这些文件和标记被配置为在不同的环境中运行。因此,如果有一种简单的方法来配置哪些测试要并行运行,而其余的测试要使用标记按顺序运行--那就太好了。

相关问题