I added in my pom.xml the following plugin to run test classes in parallel
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<parallel>classes</parallel>
<threadCount>10</threadCount>
<systemPropertyVariables>
<profile.name>${profile.name}</profile.name>
</systemPropertyVariables>
<forkCount>1</forkCount>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</plugin>
And i have
#RunWith(Suite.class)
#Suite.SuiteClasses({
test_1.class,
test_2.class
})
when i run it as a junit test it runs sequential not parallel... any help ??
<forkCount>1</forkcount> means 1 thread!
The default setting is forkCount=1/reuseForks=true, which means that maven-surefire-plugin creates one new JVM process to execute all tests in one Maven module.
from: https://maven.apache.org/surefire/maven-surefire-plugin/examples/fork-options-and-parallel-execution.html#Forked_Test_Execution
To run them in parallel, you should choose a forkCount > 1, and (to be safe) also <reuseForks>false</reuseForks>.
Related
I am running testng.xml file using POM.xml by adding compiler and surefire plugins. It runs test but the sequence of tests is not as expected.
I have 10 classes mentioned in testng.xml and it runs in that sequence when i run through testng.xml. But when running through POM.xml the sequence goes like; first it runs all the 0 priority tests mentioned in all classes, then 1 priority tests and so on. It should run tests according to the classes sequence mentioned in testng.xml.
Any quick help will be much appreciated.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>${jdk.level}</source>
<target>${jdk.level}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
under testng dependency the scope tag needed to be changed to compile from test and it resolved the issue as it needed to compile the build after adding plugins.
It resolved the issue.
all tests run instantly and load the computer
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
<configuration>
<includes>
<include>**/*CucumberRegressionRunner.java</include>
</includes>
<parallel>all</parallel>
<useSystemClassLoader>false</useSystemClassLoader>
<perCoreThreadCount>false</perCoreThreadCount>
<forkCount>2.5c</forkCount>
<reuseForks>true</reuseForks>
<threadCount>2</threadCount>
</configuration>
</plugin>
i want to run not all package, i need to run only 2-5 tests in parallel
As the answer of this post describes, you can create an execution for the tests, that should run parallel and an execution for the tests, that should not run parallell.
I am trying to execute each method of a JUnit test into a separated VM without executing all the methods at the same time. I want to serialize the execution of the test methods using a separated VM for each of them.
I have tried several configuration and checked the Maven plugin documentation about forked VM but I did not manage to get the correct behavior.
I am using the following configuration but all the methods are executed at the same time.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<reuseForks>false</reuseForks>
<parallel>methods</parallel>
<threadCountMethods>1</threadCountMethods>
</configuration>
</plugin>
The number of threads is counted by code by default (https://maven.apache.org/surefire/maven-failsafe-plugin/integration-test-mojo.html#perCoreThreadCount). The following configuration is working.
<configuration>
<reuseForks>false</reuseForks>
<parallel>methods</parallel>
<threadCount>1</threadCount>
<perCoreThreadCount>false</perCoreThreadCount>
</configuration>
I want to run my Junit on my build jar's, but maven surefire plugin executed on class file before package phase that is at test phase, is there any way to run all junit after building a jar of project.
Reason to run on build jar is to verify obfuscation of jar.
Solution is to use the maven-failsafe-plugin which will in the integration test phase. You need to this to your pom file:
<project>
[...]
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.19.1</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
[...]
</project>
You should following the conventions and follow the naming conventions of integration tests:
<includes>
<include>**/IT*.java</include>
<include>**/*IT.java</include>
<include>**/*ITCase.java</include>
</includes>
Afterwards you can run those integration tests via:
mvn clean verify
If you like to run only unit tests:
mvn clean test
There are two phase of tests in maven, one is unit test, second is integration tests. So if You want, You should execute it in integration tests phase.
I'm wondering if there is a way to specify in Maven which collection of JUnit tests run based on package names. An 'exclude' would be ideal, since I have fewer that I need not run than I have those that need to run.
Yes you can configure surefire plugin to include certain tests only
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.17</version>
<configuration>
<includes>
<include>com/abc/*Test.java</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
http://maven.apache.org/surefire/maven-surefire-plugin/examples/inclusion-exclusion.html