【问题标题】:Parallel execution with maven-surefire-plugin is throwing PluginResolutionException使用 maven-surefire-plugin 并行执行抛出 PluginResolutionException
【发布时间】:2020-01-06 08:22:21
【问题描述】:

我正在尝试通过 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 之间存在链接,一件事是肯定的,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的建议更改依赖项和插件后,它的外观是这样的

【问题讨论】:

  • 您正在使用 cucumber 4,它提供并行执行作为选项。我认为使用该选项是实现并行执行而不是依赖surefire插件的更好方法。
  • 这是我的练习程序,我的项目使用的是cucumber 3.XX版本,要在那里实现并行编程,我们需要使用以上配置,请建议我应该如何选择版本。
  • @Sureshmani 如 git hub 页面github.com/temyers/cucumber-jvm-parallel-plugin 中所述,不再支持黄瓜 jvm 并行插件,最后一次更新是在 2018 年 4 月,我知道它现在可以工作,但是对于不再需要我应该选择使用什么。请建议
  • 我建议迁移到黄瓜 4。这里有很好的文档 - cucumber.io/docs/guides/parallel-execution
  • @Sureshmani,我已经尝试过链接中提到的,不幸的是,它对我不起作用,不知道我在哪里做错了,最重要的是,更改后,我的测试运行文件显示所有像不支持或不推荐那样运行选项,请参阅上面附加的屏幕截图

标签: maven selenium-webdriver pom.xml maven-surefire-plugin parallel-execution


【解决方案1】:

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

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

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

更改 3:我已经意识到 cucumber-jvm-parallel-plugin 无法识别步骤 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

测试源)

【讨论】:

    最近更新 更多