Skip Tests Maven

Skip Tests Maven

For denpendency management using maven tool makes easy to manage the project where you can easily do validate, compile, test, package, integration-test, verify, install and deploy. This steps happens in order, means if you just execute install commnad then it will perfrom all previous steps (validate, compile, test, package, integration-test, verify) before executing install command. Sometime you don’t want to do all and would like to skip some of the command which is not needed.

  • Suppose if you want to skip test you could use below where we are setting skipTests true.
<project>
  [...]
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.12.4</version>
        <configuration>
          <skipTests>true</skipTests>
        </configuration>
      </plugin>
    </plugins>
  </build>
  [...]
</project>
  • Above is project level setting and all the time test will be skipped. You could also skip the test if you are using command line as below:

mvn install -DskipTests

  • If you don’t want to do any of the above setting and just want to skip compiling the test then you could use below:

mvn install -Dmaven.test.skip=true

  • If you want to skip test all time by defualt you could use below:
<project>
  [...]
  <properties>
    <skipTests>true</skipTests>
  </properties>
  [...]
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.12.4</version>
        <configuration>
          <skipTests>${skipTests}</skipTests>
        </configuration>
      </plugin>
    </plugins>
  </build>
  [...]
</project>
  • If you want to reenable it in command line while running install command you could use below:

mvn install -DskipTests=false

Leave a Reply

Your email address will not be published. Required fields are marked *