0

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>    
vikramvi
  • 3,312
  • 10
  • 45
  • 68

1 Answers1

0

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>

Sumit Kumar
  • 375
  • 1
  • 11
  • Are you using JUnit 4.7+? .If not please use junit version greater than 4.7. – Sumit Kumar Feb 08 '17 at 14:35
  • I'm using 4.12 and have explicitly mentioned in my pom.xml as well. It's really strange why your solution doesn't work. Please let me know if it works in your case ? if yes can you please share your pom.xml ? – vikramvi Feb 08 '17 at 14:48
  • Can you share your pom.xml? – Sumit Kumar Feb 08 '17 at 14:49
  • Thanks a ton for your time, but the problem with this approach is all the test methods' steps are getting mixed up. Instead of single test method getting executed fully on a device, it is sending instruction to random devices. "...but you may be more vulnerable towards race conditions or other unexpected and hard to reproduce behavior..." from documentation. I'm not sure if there is bug with this plugin as well. – vikramvi Feb 08 '17 at 17:23