【问题标题】:Cucumber Tests not runinng in Parallel黄瓜测试未并行运行
【发布时间】:2020-04-14 21:32:42
【问题描述】:

我是黄瓜测试框架的新手。我的目标是使用 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 运行黄瓜测试时,两个场景都使用不同的线程运行。 但是我使用创建的运行程序文件(CucumberTests)运行,两者都使用相同的线程运行。如何使用 runner 类让它们以不同的线程运行?

【问题讨论】:

    标签: java junit cucumber maven-surefire-plugin


    【解决方案1】:

    如果你想通过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>
    

    【讨论】:

      猜你喜欢
      • 2019-12-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-13
      • 1970-01-01
      • 2020-12-19
      相关资源
      最近更新 更多