我是 cucumber 测试框架的新手。我的目标是使用 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 = {"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 运行 cucumber 测试时,两个场景都使用不同的线程运行。 但我使用创建的运行程序文件(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>
关于java - cucumber 测试未并行运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61217588/