I have a Kotlin project using a Maven build. The test class names adhere to the conventions, i.e.:
*Test.ktfor unit tests (JUnit)*IT.ktfor integration tests (Spring Boot)
To speed up my Jenkins build I would like to run the unit tests and integration tests in parallel using Jenkins' parallel executor. There is no specific configuration in the pom.xml, so I expect the following to work:
- compile all classes and test classes
- run the unit tests by running the maven stage directly using the Surefire plugin (i.e. without preceding stages):
mvn surefire:test - run the integration tests the same way but using the Failsafe plugin:
mvn failsafe:integration-test
From my Jenkinsfile:
// Jenkinsfile
...
stage("Compile") {
steps {
script {
sh "./mvnw clean compile test-compile"
}
}
}
stage("Test") {
parallel {
stage("Unit Tests") {
steps {
script {
sh "./mvnw surefire:test"
}
}
}
stage("Integration Tests") {
steps {
sh "./mvnw failsafe:verify"
}
}
}
}
}
...
However, that does not seem to work, because no tests are run (neither unit- nor integration-tests).
When running mvn test the unit tests are correctly run.
mvn integration-test does not run any of the integration tests with the suffix ..IT. I assume that's because it uses the Surefire plugin (which has different naming conventions for integration tests) and not the Failsafe plugin.
It also runs the unit tests again, I assume because the test stage precedes the integration-test stage.
What is the recommended way to run unit-tests and integration-tests in parallel without having to compile twice?