Maven - How to compile tests without running them ?

Is there a way in Maven to compile the tests without running them ? I want to use the IDE to run specific tests and not all of them.


Solution 1:

How about the test-compile lifecycle phase? It doesn't require any test skipping, because it occurs before the test phase. I.e.,

$ mvn test-compile

And done.

Introduction to the Build Lifecycle explains further.

Solution 2:

To just compile the tests and code, without running them, just do:

mvn test-compile

Solution 3:

When executing a goal that will include the testing phase (such as package), you can do two things:

  • Use the command mvn -DskipTests=true package. This will compile all tests but not run them.
  • Or mvn -Dmaven.test.skip=true package. This will not compile or run the test branch.

Solution 4:

you can try to use parameter -DskipTests

References:

  • Maven Surefire Plugin # skipTests