首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用maven-surefire-plugin并行执行正在抛出PluginResolutionException。

使用maven-surefire-plugin并行执行正在抛出PluginResolutionException。
EN

Stack Overflow用户
提问于 2019-09-03 12:08:55
回答 1查看 1.6K关注 0票数 0

我试图通过TestRunner.java文件(在pom.xml中提到它们)并行地执行我的特性文件,使用maven-surefire-plugin,为此我为其设置了下面的pom.xml,但当我将pom.xml作为maven测试运行时,当版本为3.0.0-M3时,它抛出PluginResolutionException,当我将版本更新为2.19.1时,maven测试没有运行我的特性文件,但是构建显示为成功的。

  • 我试过不同的版本,但没有起作用。
  • 此外,我还尝试用以下更改替换配置部分

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

代码语言:javascript
复制
<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:在阅读了下面的文章parallel之后

我了解到在我的项目中使用的Junit版本和surefireflugin之间有联系,有一点是肯定的,Junit和maven-surefire插件的正确组合是非常必要的,我已经尝试了下面的组合

代码语言:javascript
复制
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如下所示

代码语言:javascript
复制
        <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的建议更改依赖项和插件之后,它是这样的。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-09-05 16:38:35

最后,我能够解决这个问题,对我最初的pom,已经开始做下面的修改。它并行运行我的功能文件。

更改1:我碰巧添加了黄瓜-jvm并行插件的依赖项以及插件,所以我删除了插件。

改变2:我已经意识到当我放置src/main/java时,黄瓜-jvm并行插件无法识别这些特性文件,一些帖子说我必须将所有的特性文件移到src/main/resources/feature,其中的特性是包的。

更改3:我已经意识到黄瓜-jvm并行插件无法识别像步骤def和驱动程序等资源,所以我使用了plugin,其中我声明了下面的资源

代码语言:javascript
复制
<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生命周期中的黄瓜-jvm-并行插件,因为出于某种原因,maven无法在它执行Eclipse -> Windoes > Preferences ->Maven-> life >复制粘贴下面的代码中考虑这个插件

代码语言:javascript
复制
<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

测试源)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57771477

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档