我是黄瓜测试框架的新手。我的目标是使用Junit和Maven并行运行方案文件。我已按照以下步骤操作:https://cucumber.io/docs/guides/parallel-execution/
我有两个功能文件
功能1:
Feature: Scenarios feature file One
Scenario: Scenario Number One
When request is sent to fetch data with user one
Then check the result
功能2:
Feature: Scenarios feature file One
Scenario: Scenario Number Two
When request is sent to fetch data with user two
Then check the result
我也有一个运行程序文件,如下所示:
@RunWith(Cucumber.class)
@CucumberOptions(features = { "classpath:features" },
strict = true,
glue = {"com.bfm.integration.cucumber.step"},
plugin = {"pretty", "html:target/report/cucumber", "json:target/report/cucumber/cucumber.json"},
tags = {"not @Disabled"}
)
public class CucumberTests {
}
我的POM如下:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<parallel>methods</parallel>
<useUnlimitedThreads>true</useUnlimitedThreads>
</configuration>
</plugin>
</plugins>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
<version>4.12</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>4.4.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>4.4.0</version>
<scope>test</scope>
</dependency>
[当我通过mvn clean install运行黄瓜测试时,两个方案都使用不同的线程运行。但是我使用创建的运行程序文件(CucumberTests)来运行,并且都使用同一线程运行。如何使用Runner类使它们在不同的线程上运行?
如果要由Test类并行运行它,则需要将测试类扩展到TestNG,请尝试一下
public class CucumberTests extends AbstractTestNGCucumberTests{
@Override
@DataProvider(parallel = true)
public Object[][] scenarios() {
return super.scenarios();
}
}
您已并行使用方法方法-使用插件-也有classesAndMethods选项,请进行探索]
<configuration>
<parallel>classesAndMethods</parallel>
useUnlimitedThreads>true</useUnlimitedThreads>
</configuration>