Java 在Jenkins中必须传递哪些参数才能运行与线程计数并行的测试

Java 在Jenkins中必须传递哪些参数才能运行与线程计数并行的测试,java,maven,selenium,jenkins,Java,Maven,Selenium,Jenkins,我的selenium测试套件运行良好。我使用cucumber、Selenium和Java(Maven项目)的混合,并运行Jenkins的套件 现在我想从Jenkins并行运行我的整个测试套件(5个测试应该并行运行)。我已经编写了这样的代码,每个测试都在一个单独的线程中运行 有人能告诉我需要在目标和选项中配置哪些参数吗? 我还有其他方法可以做到这一点吗 我的junit类如下所示: 下面是我的junit课程: @RunWith(Cucumber.class) @CucumberOptions(

我的selenium测试套件运行良好。我使用cucumber、Selenium和Java(Maven项目)的混合,并运行Jenkins的套件

现在我想从Jenkins并行运行我的整个测试套件(5个测试应该并行运行)。我已经编写了这样的代码,每个测试都在一个单独的线程中运行

有人能告诉我需要在目标和选项中配置哪些参数吗? 我还有其他方法可以做到这一点吗

我的junit类如下所示: 下面是我的junit课程:

@RunWith(Cucumber.class)
@CucumberOptions(
        features="classpath:",
        glue={"stepdefinitions","helpers"},
        plugin = {"pretty", "html:target/cucumber","json:target/cucumber/cucumber.json"}
    )
public class RunnerTest { }
My pom.xml:

<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>LinenHousePOC</groupId>
    <artifactId>LinenHousePOC</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <properties>
        <thread.count.methods>3</thread.count.methods>
    </properties>
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>1.2.4</version>
        </dependency>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-picocontainer</artifactId>
            <version>1.2.4</version>
        </dependency>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-junit</artifactId>
            <version>1.2.4</version>
        </dependency>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-testng</artifactId>
            <version>1.1.5</version>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>2.53.1</version>
        </dependency>
        <dependency>
            <groupId>com.relevantcodes</groupId>
            <artifactId>extentreports</artifactId>
            <version>2.41.0</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.5.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.19.1</version>
                <configuration>
                    <parallel>methods</parallel>
                    <perCoreThreadCount>false</perCoreThreadCount>
                    <useUnlimitedThreads>true</useUnlimitedThreads>
                    <threadCountMethods>${thread.count.methods}</threadCountMethods>
                    <forkCount>1</forkCount>
                    <reuseForks>true</reuseForks>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

4.0.0
林豪斯波克
林豪斯波克
0.0.1-快照
3.
朱尼特
朱尼特
4.11
测试
信息杯
黄瓜爪哇
1.2.4
信息杯
黄瓜皮容器
1.2.4
信息杯
黄瓜刺柏
1.2.4
信息杯
黄瓜试验
1.1.5
org.seleniumhq.selenium
硒爪哇
2.53.1
相关代码
扩展端口
2.41.0
org.apache.maven.plugins
maven编译器插件
3.5.1
1.8
1.8
org.apache.maven.plugins
maven surefire插件
2.19.1
方法
假的
真的
${thread.count.methods}
1.
真的
当你说你有“一个运行程序文件”时,我假设你说的是一个JUnit套件文件或一个自定义运行程序,它是block JUnit 4 runner类的子类。如果您使用的是JUnit>=4.7,那么可以使用maven surefire插件上的一些设置来控制并行测试的执行。我将在这里发布到文档的链接,因为您可以做很多可能的设置,这完全取决于您需要做什么,以及在资源使用、所需并行量、并行争用点(例如共享状态)方面需要考虑什么,一般来说,这些设置可以直接放在POM文件中,而不是从Jenkins处进行配置,尽管我已经成功地在
POM
文件中定义了这些设置,并具有可以从Jenkins处覆盖的属性,以便于自定义

示例
pom.xml
(不是全部,只是关于surefire及其属性的部分):


1.

现在如何启动测试?如果您使用的是标准maven插件,那么它不应该与Jenkins配置有任何关系。您的测试框架是什么?junit?testng?你是如何使它们平行的?我这边有很多问题,你也有很多可能的答案;),你能发布你的全部技术吗?我正在使用junit运行我的测试套件。我只有一个跑步者档案。在Jenkins中,我将作业配置为maven项目,指定源路径,然后在我给出的目标中配置为“clean test-Dbrowser=$BrowserName”,它一个接一个地运行整个套件的测试。但是我想并行执行这些测试。我的一个朋友告诉我,如果我们指定-Pparallel标记和线程计数,它应该并行运行,但我不确定。Aaron,非常感谢您花时间给出这个详细的解释。我试过你建议的方法,但没有成功。我很困惑我在这里错过了什么。实际上,在cucumber中,我们开发了一个运行程序文件(junit类),它调用功能文件。这些功能文件调用各自的、类和方法。我已经用junit类和pom.xml.Ah更新了我的查询,我从未使用过cucumber。很可能该实现与常规maven并行方法执行不兼容。。。也可能是以另一种方式。对不起,上面的方法不适合你!Uday,我已经更新了答案,添加了一个我发现可能有用的帖子的链接。但是请注意,我自己还没有尝试过其中的任何步骤。祝你好运!:-)
<!-- POM Properties -->

<properties>
    <thread.count.methods>1</thread.count.methods>
</properties>

<!-- Build Settings -->

<build>
    <plugins>
        <plugin>
            <artifactId>maven-surefire-plugin</artifactId>
            <groupId>org.apache.maven.plugins</groupId>
            <version>2.19.1</version>
            <configuration>
                <parallel>methods</parallel>
                <!-- Specify the number of threads ... this sets a hard limit no matter how many cores -->
                <perCoreThreadCount>false</perCoreThreadCount>
                <useUnlimitedThreads>true</useUnlimitedThreads>
                <threadCountMethods>${thread.count.methods}</threadCountMethods>
                <!-- Only use 1 JVM instance for all tests -->
                <forkCount>1</forkCount>
                <reuseForks>true</reuseForks>
            </configuration>
        </plugin>
    </plugins>
</build>