【问题标题】:maven-failsafe-plugin does not execute test cases from single class in parallel modemaven-failsafe-plugin 不在并行模式下从单个类执行测试用例
【发布时间】:2017-02-08 13:59:17
【问题描述】:

我有一个包含多个测试用例的测试类,我想以并行模式执行。

我在 pom.xml 中进行了以下设置

但测试用例不是以并行模式执行,而是按顺序执行。

请澄清这里可能出了什么问题?

<plugin>
            <artifactId>maven-failsafe-plugin</artifactId>
            <version>2.18.1</version>
            <configuration>
                <forkCount>3</forkCount>
                <reuseForks>true</reuseForks>            
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>integration-test</goal>
                        <goal>verify</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>    

【问题讨论】:

    标签: maven pom.xml maven-failsafe-plugin


    【解决方案1】:

    在 maven-failsafe-plugin 中直接添加并行配置不起作用(可能是一个错误。)

    但我们可以在surefire插件配置中设置并行属性和线程数。

    在内部 ma​​ven-failsafe-plugin 下载 ma​​ven-surefire-plugin 插件。

    所以我们可以显式地提供对具有并行配置的 maven-surefire-plugin 的依赖。

    我已经测试过,方法正在并行执行。

    如需了解如何并行运行测试用例和更多配置参数,请点击here

                 <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>2.19.1</version>
                    <configuration>
                        <forkCount>3</forkCount>
                        <reuseForks>true</reuseForks>
                        <parallel>methods</parallel>
                        <useUnlimitedThreads>true</useUnlimitedThreads>
                    </configuration>
                 <plugin> 
    

    工作 pom。

    <project>
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.mycompany.app</groupId>
    <artifactId>my-module</artifactId>
    <version>1</version>
    
    
    <dependencies>
    
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
    
    
    
    </dependencies>
    
    <build>
        <plugins>
    
            <plugin>
    
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.19.1</version>
                <configuration>
                    <forkCount>3</forkCount>
                    <reuseForks>true</reuseForks>
                    <parallel>methods</parallel>
                    <useUnlimitedThreads>true</useUnlimitedThreads>
                </configuration>
    
            </plugin>
    
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>2.19.1</version>
    
            </plugin>
    
    
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
            </plugin>
    
        </plugins>
    
    </build>
    

    【讨论】:

    • 您使用的是 JUnit 4.7+ 吗? .如果不是请使用大于4.7的junit版本。
    • 我使用的是 4.12,并且在我的 pom.xml 中也明确提到过。为什么你的解决方案不起作用真的很奇怪。请让我知道它是否适用于您的情况?如果可以,请分享您的 pom.xml 吗?
    • 你能分享你的 pom.xml 吗?
    • 非常感谢您抽出宝贵时间,但这种方法的问题是所有测试方法的步骤都搞混了。它不是在设备上完全执行单一测试方法,而是向随机设备发送指令。 “......但您可能更容易受到竞争条件或其他意外且难以重现的行为......”来自文档。我不确定这个插件是否也有错误。
    猜你喜欢
    • 1970-01-01
    • 2012-02-11
    • 1970-01-01
    • 2019-05-08
    • 2011-12-09
    • 1970-01-01
    • 1970-01-01
    • 2016-04-11
    • 1970-01-01
    相关资源
    最近更新 更多