0

我正在尝试通过 TestRunner.java 文件(通过在 pom.xml 中提及它们)执行我的功能文件,同时使用 maven-surefire-plugin,我已经为它设置了 pom.xml,如下所示,但是当我运行 pom.xml 时。 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的建议更改依赖项和插件后,这就是它的外观 在此处输入图像描述

4

1 回答 1

0

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

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

更改 2:我意识到 cucumber-jvm-parallel-plugin 在放置 src/main/java 时无法识别功能文件,一些帖子说我必须将所有功能文件移动到 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

测试源)

于 2019-09-05T16:38:35.693 回答