简体   繁体   English

无法控制 cucumber 的并行执行

[英]Unable to control parallel execution for cucumber

I am unable to control the treads from dataproviderthreadcount.我无法控制来自 dataproviderthreadcount 的踏板。 For example if we have 4 scenario and I run my script, it execute all 4 scenario's parallelly.例如,如果我们有 4 个场景并且我运行我的脚本,它会并行执行所有 4 个场景。 Doesn't matter what dataproviderthreadcount value I gave in the pom for maven-surfire.我在 pom 中为 maven-surfire 提供的 dataproviderthreadcount 值并不重要。

Below are the snapshots.以下是快照。

POM:聚甲醛:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.example</groupId>
    <artifactId>testParallerRun</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <cucumbertestng.version>5.6.0</cucumbertestng.version>
        <cucumberjava.version>5.6.0</cucumberjava.version>
        <mvncompiler.version>3.8.1</mvncompiler.version>
        <javarelease.version>11</javarelease.version>
        <mvnsurefire.version>3.0.0-M5</mvnsurefire.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-testng</artifactId>
            <version>${cucumbertestng.version}</version>
        </dependency>
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>${cucumberjava.version}</version>
        </dependency>
    </dependencies>

    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>${mvncompiler.version}</version>
                    <configuration>
                        <release>${javarelease.version}</release>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>${mvnsurefire.version}</version>
                    <configuration>
                        <properties>
                            <property>
                                <name>dataproviderthreadcount</name>
                                <value>2</value>
                            </property>
                        </properties>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>
</project>

Runner Class:跑步者 Class:

package com.test.runner;


import io.cucumber.testng.AbstractTestNGCucumberTests;
import io.cucumber.testng.CucumberOptions;
import org.testng.annotations.DataProvider;


@CucumberOptions(
        plugin = {
                "pretty",
                "json:target/reports/json/result.json",
                "html:target/reports/html/result.html"},
        strict = true,
        features = {"src/test/resources/"},
        glue = {"com.test.stepdef"},
        tags = {""}
)

public class TestRunner extends AbstractTestNGCucumberTests {
    @DataProvider(parallel = true)
    @Override
    public Object[][] scenarios() {
        return super.scenarios();
    }
}

Feature 1:特点 1:

Feature: test 1

  Scenario: 01
    Given Print "01"

  Scenario: 02
    Given Print "02"

  Scenario: 03
    Given Print "03"

  Scenario: 04
    Given Print "04"

Please let me if anyone know how to control the number of threads rather than let Testng decide.如果有人知道如何控制线程数而不是让 Testng 决定,请告诉我。

There's no problem with TestNG per se here. TestNG 本身在这里没有问题。

The dataproviderthreadcount attribute that you have set in your pom file is going to be applicable and relevant only when you are running your test via mvn clean test .您在 pom 文件中设置的dataproviderthreadcount属性仅在您通过mvn clean test运行测试时才适用且相关。

If you are trying to run this test class from within the IDE (IntelliJ or Eclipse for that matter) its not going take affect.如果您尝试从 IDE(IntelliJ 或 Eclipse)中运行此测试 class,它不会生效。

Here's a test class that I created which is powered by a data provider ( For the sake of simplicity I have intentionally kept cucumber out of the equation )这是我创建的由数据提供者提供支持的测试 class (为简单起见,我有意将 cucumber 排除在等式之外)

import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

public class AppTest {

  @Test(dataProvider = "dp")
  public void shouldAnswerWithTrue(int i) {
    System.err.println("Running on [" + Thread.currentThread().getId() + "]");

  }

  @DataProvider(name = "dp", parallel = true)
  public Object[][] testData() {
    return new Object[][]{
        {1},
        {2},
        {3},
        {4},
        {5},
        {6}
    };
  }
}

Here's the command line output when I run mvn clean test这是我运行mvn clean test时的命令行 output

[INFO] --- maven-surefire-plugin:3.0.0-M5:test (default-test) @ testng_playground ---
[INFO] 
[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] Running com.rationaleemotions.AppTest
Running on [15]
Running on [14]
Running on [15]
Running on [14]
Running on [14]
Running on [15]
[INFO] Tests run: 6, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.62 s - in com.rationaleemotions.AppTest
[INFO] 
[INFO] Results:
[INFO] 
[INFO] Tests run: 6, Failures: 0, Errors: 0, Skipped: 0

I encountered the exact same.我遇到的完全一样。 As Krishnan mentioned, the dataproviderthreadcount in pom.xml works only when you run mvn test but without any parameter.正如 Krishnan 提到的,pom.xml 中的 dataproviderthreadcount 仅在您运行mvn test但没有任何参数时有效。 If you want to specify which suite xml to run, you will need to add -Ddataproviderthreadcount=2 in command line as well.如果要指定运行哪个套件 xml,还需要在命令行中添加-Ddataproviderthreadcount=2 For example, " mvn -Dsurefire.suiteXmlFiles=suite.xml -Ddataproviderthreadcount=2 test "例如,“ mvn -Dsurefire.suiteXmlFiles=suite.xml -Ddataproviderthreadcount=2 测试

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM