There may be some misconfigurations in your specification. You declare useUnlimitedThreads=true
but then threadCountMethods=5
, and they don't seem to get along with each other:
The parameter useUnlimitedThreads allows for an unlimited number of threads. Unless useUnlimitedThreads is set to "true", the parameter threadCount can be used with the optional parameter perCoreThreadCount.
Also, I'm not sure about your <include>${tests}</include>
.
Anyways, I would just start over from your requirement. Since it is pretty basic, I would recommend to try a simple configuration like the following:
<plugins>
[...]
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<parallel>methods</parallel>
<threadCount>5</threadCount>
</configuration>
</plugin>
[...]
</plugins>
http://maven.apache.org/surefire/maven-surefire-plugin/examples/junit.html
- make sure to be using JUnit > 4.7 (check in your
<dependencies>
)
- make sure to follow maven conventions about the name and the location of the test classes, i.e. they need to be placed under
src/test/java
, and the files be named XYXTest.java
- that should be it
About parallel=classesAndMethods
, which was specified in the question: I don't think you need it; I'd rather go with a simple parallel=methods
, as above. I'm not 100% sure of the different behavior, as I can't find any explanation on maven surefire's web site, but I guess that with classesAndMethods
you will have test methods from different classes running at the same time (on different threads). Whereas with parallel=methods
you will have running at the same time only test methods from one class; that is, the runner will pick each test class, and run its methods, sequentially, in one thread.
The problem with parallel=classesAndMethods
is that the greater the level of concurrency, the bigger the headaches in case two test classes have some kind of dependencies (think of two test classes that use a production class which is static and maintains a static state).