Maven - Failsafe 插件不是 运行 并行黄瓜测试

Maven - Failsafe plugin is not running cucumber tests in parallel

我正在尝试将宁静黄瓜测试设置为 运行 并行

我已经添加了所有提到的必要配置,但由于某些原因,测试是在单个线程中执行的。我尝试了 forkCount、threadCount、parallel、useUnlimitedThreadCounts 等的各种组合,但似乎没有任何效果。

还尝试了对 JUnit 4 和 5 的依赖,但效果不佳。

Pom.xml

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

    <properties>
        <serenity.version>2.2.5</serenity.version>
        <serenity.maven.version>2.2.5</serenity.maven.version>
        <serenity.cucumber5.version>2.2.2</serenity.cucumber5.version>
        <cucumber.version>5.6.0</cucumber.version>
        <selenium.version>3.141.59</selenium.version>
    </properties>

    <dependencies>
        <!-- Cucumber -->
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-core</artifactId>
            <version>${cucumber.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-junit</artifactId>
            <version>${cucumber.version}</version>
            <scope>test</scope>
        </dependency>

        <!-- Serenity -->
        <dependency>
            <groupId>net.serenity-bdd</groupId>
            <artifactId>serenity-core</artifactId>
            <version>${serenity.version}</version>
            <exclusions>
                <exclusion>
                    <groupId>io.cucumber</groupId>
                    <artifactId>cucumber-core</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>net.serenity-bdd</groupId>
            <artifactId>serenity-cucumber5</artifactId>
            <version>${serenity.cucumber5.version}</version>
        </dependency>

        <!-- Selenium -->
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>${selenium.version}</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>3.0.0-M4</version>
                <dependencies>
                    <dependency>
                        <groupId>org.apache.maven.surefire</groupId>
                        <artifactId>surefire-junit47</artifactId>
                        <version>3.0.0-M4</version>
                    </dependency>
                </dependencies>
                <configuration>
                    <parallel>classes</parallel>
                    <threadCount>2</threadCount>
                    <forkCount>2C</forkCount>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>integration-test</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

用于验证的 Maven 调试日志表明 parallelMavenExecution 出于某种原因被设置为 false。

[DEBUG] Configuring mojo org.apache.maven.plugins:maven-failsafe-plugin:3.0.0-M4:integration-test from plugin realm ClassRealm[plugin>org.apache.maven.plugins:maven-failsafe-plugin:3.0.0-M4, parent: jdk.internal.loader.ClassLoaders$AppClassLoader@4f8e5cde]
[DEBUG] Configuring mojo 'org.apache.maven.plugins:maven-failsafe-plugin:3.0.0-M4:integration-test' with basic configurator -->
[DEBUG]   (s) additionalClasspathElements = []
[DEBUG]   (s) basedir = /Users/vinothraj/IdeaProjects/hiscox-usa-portal-testsuite
[DEBUG]   (s) childDelegation = false
[DEBUG]   (s) classpathDependencyExcludes = []
[DEBUG]   (s) defaultClassesDirectory = /target/classes
[DEBUG]   (s) dependenciesToScan = []
[DEBUG]   (s) disableXmlReport = false
[DEBUG]   (s) enableAssertions = true
[DEBUG]   (f) excludedEnvironmentVariables = []
[DEBUG]   (f) forkCount = 2C
[DEBUG]   (s) forkMode = once
[DEBUG]   (s) forkedProcessExitTimeoutInSeconds = 30
[DEBUG]   (s) junitArtifactName = junit:junit
[DEBUG]   (s) localRepository =       id: local
      url: file:///.m2/repository/
   layout: default
snapshots: [enabled => true, update => always]
 releases: [enabled => true, update => always]

[DEBUG]   (s) parallel = classes
[DEBUG]   (f) parallelMavenExecution = false
[DEBUG]   (s) parallelOptimized = true
[DEBUG]   (s) perCoreThreadCount = true

提前致谢。

您为 parallel 使用了错误的值。您必须将其设置为方法或两者。否则 Surefire 将 运行 您的 运行ner class 的所有测试连续进行。

https://github.com/cucumber/cucumber-jvm/tree/master/junit

Cucumber JUnit supports parallel execution of feature files across multiple threads. To enable this with maven set the parallel property to either methods or both.

<build>
    <plugins>
        <plugin>
            <artifactId>maven-surefire-plugin</artifactId>
            <!-- Use 2.22.1 or higher -->
            <version>${maven-surefire-plugin.version}</version>  
            <configuration>
                <parallel>both</parallel>
                <threadCount>4</threadCount>
            </configuration>
        </plugin>
    </plugins>
</build>