L4zy
L4zy

Reputation: 337

Run junit test in parallel with surefire maven plugin

It is posible to configure surefire plugin to only run some test in parallel and others in sequence?

Also can surefire forkCount be used to run parallel tests declared into a jUnit Suite?

Upvotes: 1

Views: 1445

Answers (3)

blackreaper
blackreaper

Reputation: 69

You can add this to the configuration of the maven-surefire-plugin in the pom.xml file.

<configuration>
    <parallel>all</parallel>
    <threadCount>10</threadCount>
    <threadCountSuites>2</threadCountSuites>
    <threadCountClasses>2</threadCountClasses>
    <threadCountMethods>6</threadCountMethods>
    <parallelTestTimeoutInSeconds>3.5</parallelTestTimeoutInSeconds>
    <parallelTestTimeoutForcedInSeconds>5</parallelTestTimeoutForcedInSeconds>
    <perCoreThreadCount>true</perCoreThreadCount>
    <includes>
        <include>**/FunctionTestSuite.java</include>
    </includes>
</configuration>

A detailed explanation can be found at this link. It gives a complete description step by step to run JUnit tests parallel with surefire-maven-plugin.

Note: This code snippet shows all the available options. You can change or remove some options as per your need!

Upvotes: 0

Jake
Jake

Reputation: 4670

A very easy way to do this is as follows:

  • Move sequential tests each into its own test suite in junit
  • Move parallel tests all into the same suite.
  • Set Parallel to "classes"

configuration>
					<includes>
						<include>**/A01TestSuite.java</include>
						<include>**/A02ServiceTestSuite.java</include>
						<include>**/A03FlowTestSuite.java</include>
					</includes>
					<additionalClasspathElements>
						<additionalClasspathElement>${webinf.dir}</additionalClasspathElement>
					</additionalClasspathElements>
					<systemPropertyVariables>
						<log4j.configuration>file:${l4j.test}/log4j.test.properties</log4j.configuration>
					</systemPropertyVariables>
					<forkMode>always</forkMode>
					<argLine>-Xms512m -Xmx512m</argLine>
					<parallel>classes</parallel>
					<threadCount>10</threadCount>

				</configuration>

Upvotes: 1

Guy Bouallet
Guy Bouallet

Reputation: 2125

You can use separate maven profiles with two different surefire plugin configurations.

Upvotes: 1

Related Questions