maven-failsafe-plugin does not execute test cases from single class in parallel mode

不打扰是莪最后的温柔 提交于 2019-12-12 02:12:08

问题


I've single test class with multiple test cases, which I would like to execute in parallel mode.

I've below setup in pom.xml

But instead of executing in parallel mode, test cases are being executed in sequence.

Please clarify what may be going wrong here ?

<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>    

回答1:


Directly adding parallel configuration in maven-failsafe-plugin is not working (May be a bug.)

But we can set parallel attribute and thread count in surefire plugin configuration.

Internally maven-failsafe-plugin downloads maven-surefire-plugin plugin.

So we can explicitly provide dependency on maven-surefire-plugin having parallel configuration.

I have tested , method are getting executed in parallel.

For more know how on running testcase in parallel and more configuration parameters click 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> 

Working 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>



来源:https://stackoverflow.com/questions/42115143/maven-failsafe-plugin-does-not-execute-test-cases-from-single-class-in-parallel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!