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.
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.
I have some unit tests under Integration.java. I want Maven to ignore the test results of this class as they fail rarely (due to external server maintenance). But I don't want to ignore them from running as I need them for code coverage.
I've tried this configuration
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<includes>
<include>IntegrationTest.java</include>
</includes>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</plugin>
This seems to be working by ignoring the failed tests. But the problem with the above configuration is, it is ignoring the failed tests at other classes as well.
I want all the tests under Integration.java needs to be executed but It shouldn't have any impact on the build to determine success/failure.
But, the build should fail if any test cases fail under any other Test classes other than Integration.java
Like #khmarbaise has mentioned, It needs to be handled by maven-failsafe not surefire plugin
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<includes>
<include>*IntegrationTest.java</include>
</includes>
</configuration>
<executions>
<execution>
<id>failsafe-integration-tests</id>
<phase>integration-test</phase>
<goals>
<goal>integration-test</goal>
</goals>
</execution>
</executions>
</plugin>
By using maven-failsafe-plugin I made sure the test cases run and for the good code coverage and the build will not fail even if the upstream is down.
Surefire by default includes all test classes whose name starts with Test/ends with Test/Tests/TestCase.
You can use excludes and includes parameters as per your need :
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.21.0</version>
<configuration>
<excludes>
<exclude>DataTest.java</exclude>
</excludes>
<includes>
<include>DataCheck.java</include>
</includes>
</configuration>
</plugin>
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>.
We have a project with lots of tests running against a database. Many of the tests set up the database using #BeforeClass, and clean it out using #AfterClass, which works fine when we run the tests locally. When Jenkins runs them, it mixes up the order so tests from different classes are intermixed. For instance, A.TestAlpha, B.TestFoo, A.TestGamma. Then inevitably the tests fail because they don't have the correct setup.
My understanding of Jenkins is that it's supposed to run one class of tests at a time. Is there some config somewhere that might tell it to run the tests in this weird way?
(edit)
The same sort of problems occur running tests locally with mvn.
From mvn help:effective-pom
(project)
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.17</version>
<configuration>
<includes>
<include>**/When*.java</include>
<include>**/Test*.java</include>
<include>**/*Test.java</include>
<include>**/*TestCase.java</include>
</includes>
</configuration>
</plugin>
(module)
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.17</version>
<executions>
<execution>
<id>default-test</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<includes>
<include>**/When*.java</include>
<include>**/Test*.java</include>
<include>**/*Test.java</include>
<include>**/*TestCase.java</include>
</includes>
</configuration>
</execution>
</executions>
<configuration>
<includes>
<include>**/When*.java</include>
<include>**/Test*.java</include>
<include>**/*Test.java</include>
<include>**/*TestCase.java</include>
</includes>
</configuration>
</plugin>
Thanks to everyone who attempted to help.
The bug apparently lies in TestNG.
How to make sure TestNG runs methods on test classes in succession instead of interleaved?
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