使用 maven-surefire-plugin 的并行执行抛出 PluginResolutionException

Parallel execution with maven-surefire-plugin is throwing PluginResolutionException

我正在尝试通过 TestRunner.java 文件(通过在 pom.xml 中提及它们)来执行我的功能文件,同时使用 maven-surefire-plugin,为此我设置了 pom.xml 如下,但是当我 运行 pom.xml 作为 maven 测试时,当版本为 3.0.0-M3 时它抛出 PluginResolutionException,当我将版本更新到 2.19.1 时,maven 测试是没有 运行 宁我的功能文件,但构建显示为成功

仍然没有执行我的功能文件,但是正在构建 成功

<configuration>
<forkCount>3</forkCount>
<reuseForks>true</reuseForks>
<!-- 
<parallel>classes</parallel>
<forkMode>perthread</forkMode>
<threadCount>3</threadCount>
-->
<argLine>-Xmx1024m -XX:MaxPermSize=256m</argLine>
<includes>
<include>**/*TestRunner.java</include>
</includes>
</configuration>

PS: 看完下面的文章后 https://maven.apache.org/surefire/maven-surefire-plugin/examples/junit.html#Running_tests_in_parallel

我了解到我在项目中使用的Junit版本和surefireflugin之间存在link,弓有一件事是肯定的,Junit和maven-surefire-plugin的正确组合是非常必要的,我试过以下组合

JUnit 4.7
plugin 3.0.0-M3

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>3.0.0-M3</version>
</dependency>
</dependencies>
</plugin> 

JUnit 4.12
plugin 2.20

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20</version>
<configuration>
<parallel>classes</parallel>
<threadCount>3</threadCount>
<argLine>-Xmx1024m -XX:MaxPermSize=256m</argLine>
<includes>
<include>**/*TestRunner.java</include>
</includes>
</configuration>
</plugin>

但它没有帮助,我想我在选择这个版本和配置正确参数的插件时犯了错误,请帮助我

我的完整pom如下

        <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>com.practise.raja</groupId>
            <artifactId>SeleniumConcepts</artifactId>
            <version>0.0.1-SNAPSHOT</version>
            <dependencies>
                    <dependency>
                    <groupId>junit</groupId>
                    <artifactId>junit</artifactId>
                    <version>4.12</version>
                </dependency>

                <dependency>
                    <groupId>io.cucumber</groupId>
                    <artifactId>cucumber-junit</artifactId>
                    <version>4.7.1</version>
                </dependency>

                <dependency>
                    <groupId>io.cucumber</groupId>
                    <artifactId>cucumber-picocontainer</artifactId>
                    <version>4.7.1</version>
                </dependency>
                <dependency>
                    <groupId>org.seleniumhq.selenium</groupId>
                    <artifactId>selenium-java</artifactId>
                    <version>3.5.3</version>
                </dependency>

            </dependencies>

            <build>
                <plugins>
                    <plugin>
                        <artifactId>maven-compiler-plugin</artifactId>
                        <version>3.1</version>
                        <configuration>
                            <source>1.8</source>
                            <target>1.8</target>
                            <fork>true</fork>
                            <executable>C:\Program Files (x86)\Java\jdk1.8.0_211\bin\javac</executable>
                        </configuration>
                    </plugin>

                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <version>3.0.0-M3</version>
                        <configuration>
                            <parallel>classes</parallel>
                            <forkMode>perthread</forkMode>
                            <threadCount>3</threadCount>
                            <argLine>-Xmx1024m -XX:MaxPermSize=256m</argLine>
                            <includes>
                                <include>**/*TestRunner.java</include>
                            </includes>
                        </configuration>
                    </plugin>

                </plugins>
            </build>
        </project>

预计: 我的功能文件应该 运行 并行 实际的: 我的功能文件没有执行

根据 sureshmani 的建议更改依赖项和插件后,这就是它的样子

终于我能够解决这个问题,对于我最初的 pom,已经开始进行以下更改。 运行 我的特征文件并行

更改 1:我碰巧添加了对 cucumber-jvm-parallel-plugin 的依赖以及插件,所以我删除了插件

更改 2:我意识到 cucumber-jvm-parallel-plugin 在我放置功能文件时无法识别它们 src/main/java,一些帖子说我必须移动所有功能文件到 src/main/resources/feature ,其中 features 是 package

更改 3:我意识到 cucumber-jvm-parallel-plugin 无法识别 step def 和驱动程序等资源,所以我在声明资源的地方使用了 build-helper-maven-plugin如下

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>src/main/java/</source>
<source>src/main/resources/</source>
<source>features</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>

更改 4:我的 IDE 的 maven 生命周期中的 cucumber-jvm-parallel-plugin,因为出于某种原因,maven 无法在执行时考虑此插件 Eclipse --> Windoes --> Preferences --> Maven->LifeCycleMappings-> 复制粘贴下面的代码

<pluginExecution>
<pluginExecutionFilter>
<groupId>com.github.temyers</groupId>
<artifactId>cucumber-jvm-parallel-plugin</artifactId>
<goals>
<goal>generateRunners</goal>
</goals>
<versionRange>[4.2.0,)</versionRange>
</pluginExecutionFilter>
<action>
<ignore/>
</action>
</pluginExecution>
Then , click on "Reload workspace lifecycle mapping metadata" button in Preference 
Maven modal

My final pom looks like this
<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>com.practise.raja</groupId>
<artifactId>JUnitCucumberParallelExecutionPractise</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>JUnitCucumberParallelExecutionPractise</name>
<description>JUnitCucumberParallelExecutionPractise</description>
<dependencies>
<!--        <dependency>
<groupId>com.github.temyers</groupId>
<artifactId>cucumber-jvm-parallel-plugin</artifactId>
<version>5.0.0</version>
</dependency>
-->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>4.7.1</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-picocontainer</artifactId>
<version>4.7.1</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.5.3</version>
</dependency>
</dependencies>
<properties>
<src.main.java>src/main/java</src.main.java>
</properties>
<build>
<resources>
<resource>
<directory>${src.main.java}</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>src/main/java/</source>
<source>src/main/resources/</source>
<source>features</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<fork>true</fork>
<executable>C:\Program Files (x86)\Java\jdk1.8.0_211\bin\javac</executable>
</configuration>
</plugin>
<plugin>
<groupId>com.github.temyers</groupId>
<artifactId>cucumber-jvm-parallel-plugin</artifactId>
<version> 4.2.0</version>
<executions>
<execution>
<id>generateRunners</id>
<phase>generate-test-sources</phase>
<goals>
<goal>generateRunners</goal>
</goals>
<configuration>
<featuresDirectory>src/main/resources/features</featuresDirectory>
<glue>
<package>com.qa.stepdef</package>
</glue>
<outputDirectory>${project.build.directory}/generated-test- 
sources/cucumber</outputDirectory>
<cucumberOutputDir>${project.build.directory}</cucumberOutputDir>
<format> json </format>
<strict>true</strict>
<monochrome>false</monochrome>
<useTestNG>false</useTestNG>
<namingScheme>simple</namingScheme>
<namingPattern>Parallel{c}IT</namingPattern>
<parallelScheme>FEATURE</parallelScheme>
</configuration>
</execution>
</executions>
</plugin>
<!-- Specify a custom template for the generated sources (this is a path 
relative to the project base directory) -->
<!-- <customVmTemplate>src/test/resources/custom-runner-template.java.vm 
</customVmTemplate> -->
<!-- Specify a custom package name for generated sources. Default is no 
package. -->
<!--<packageName></packageName> <plugins> <plugin> <name>json</name> 
</plugin> 
<plugin> <name>html</name> </plugin> <plugin> <name>pretty</name> </plugin> 
</plugins> -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20</version>
<configuration>
<forkCount>3</forkCount>
<reuseForks>true</reuseForks>
<includes>
<include>**/*IT.class</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
</project>

Even after these changes, an error started showing at <execution> in pom, it says 
Plugin execution not covered by lifecycle configuration: com.github.temyers:cucumber- 
jvm-parallel-plugin:4.2.0:generateRunners (execution: generateRunners, phase: 
generate-

But, its fine, i am able to run the feature files in parallel even with this above 
error

测试源)