Skip to content

/compare/maven/skiptests-vs-maven-test-skip

mvn -DskipTests vs -Dmaven.test.skip=true: what each one skips

The commands on this page have not been executed by our verification runner yet.updated
tool
Maven
compares
-DskipTests vs -Dmaven.test.skip=true

mvn package -DskipTests compiles the test sources but does not run them. mvn package -Dmaven.test.skip=true skips both compiling and running tests, so it is faster but also breaks anything that needs the compiled test classes, such as a test-jar consumed by another module. Use -DskipTests by default, and -Dmaven.test.skip=true only when the test code itself does not compile or is not needed at all.

Side by side

Criterion-DskipTests-Dmaven.test.skip=true
Compiles src/test/java (testCompile)yesno
Copies test resourcesyesno
Runs unit tests (Surefire)nono
Runs integration tests (Failsafe)older Failsafe: no; Failsafe 3.6.0: yes, unless -DskipITsno
test-jar for other modulesbuilt with the compiled test classesmissing classes; dependent modules can fail
Catches test code that no longer compilesyesno
Typical useFast local packaging, deploy jobs after a separate test jobEmergency builds when test code is broken

Commands

bash
mvn package -DskipTests                 # compile tests, do not run them
mvn package -Dmaven.test.skip=true      # do not even compile tests
mvn verify -DskipITs                    # run unit tests, skip Failsafe integration tests
mvn test -Dtest=OrderServiceTest        # run a single test class instead of skipping
mvn test -Dsurefire.failIfNoSpecifiedTests=false -Dtest='Order*'   # pattern, no failure if a module has none

Setting it in pom.xml

pom.xml
<properties>
  <!-- default for this project; override with -DskipTests=false -->
  <skipTests>true</skipTests>
</properties>

What each property actually does

skipTests is a parameter of the Surefire plugin: the test phase still runs every step before it (compiling main code, copying test resources, compiling tests), and only the execution is skipped. maven.test.skip is read by more plugins: the Compiler Plugin skips testCompile, the Resources Plugin skips testResources, and Surefire and Failsafe skip execution. Nothing in target/test-classes is produced.

PropertyRead byEffect
skipTestsSurefire (and Failsafe before 3.6.0)Do not run tests; still compile them
maven.test.skipCompiler, Resources, Surefire, FailsafeDo not compile or run tests
skipITsFailsafeDo not run integration tests; unit tests still run
maven.test.skip.execSurefire, FailsafeOlder, deprecated way to skip execution only

Which one to use

  • Default choice: -DskipTests. The build stays honest about test code that no longer compiles, and modules that publish a test-jar keep working.
  • Integration tests only: -DskipITs keeps unit tests and skips the slow Failsafe suite, for example on every push, with the full mvn verify on a schedule or before release.
  • Test code is broken and you need an artifact now: -Dmaven.test.skip=true, as a one-off. Fix the tests before the next release.
  • Never by default in CI: a pipeline that deploys should run at least one full mvn verify.

FAQ

Does -DskipTests skip integration tests?

It depends on the Failsafe version. Older Failsafe releases bound their skipTests parameter to the same property, so -DskipTests skipped both. The Failsafe 3.6.0 documentation says the parameter is no longer bound to it: use -DskipITs, or -Dmaven.test.skip=true to skip everything.

Why does my build fail with -Dmaven.test.skip=true but work with -DskipTests?

Something needs the compiled test classes, typically a module that depends on another module's test-jar. With maven.test.skip the classes are never compiled, so that jar is empty or missing.

How do I run tests again when skipTests is true in the pom?

Pass -DskipTests=false on the command line; a user property overrides the value set in the properties section.

Sources