java - cucumber 测试未并行运行

标签 java junit cucumber maven-surefire-plugin

我是 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/

相关文章:

java - 无法使用 OAuth 2 通过 Jakarta Mail 连接到 Office 365 SMTP 服务器

java - JUnit 测试仅在调用 Assert 后捕获异常

spring - 使用 JUnit 测试 Spring 应用程序时出现问题 : NoSuchBeanDefinitionException raised only in tests

java - JUnit:NoClassDefFoundError:org/junit/runner/manipulation/Filter

ruby - 从 span 标签中读取文本值

ruby - 查找按钮的所有 XPath 并选择最后一个?

java - 使用 spring 部署应用程序后如何启动 ActiveMQ messageListener?

Java 微服务无法与 AWS Athena 客户端通信 : Handshake_Failure

ruby - 当 Ruby 正则表达式不适合在线时

Java 内存不足堆空间