Build Maven Project Without Running Unit Tests

Unit TestingMaven 2

Unit Testing Problem Overview


How do you build a Maven project without running unit tests?

Currently restructuring some code I have for a Servlet and would like to try it out in my web browser (which means running mvn install to get the .war to upload to Tomcat). I'm fully aware my UNIT tests are failing and I'm fine with that because I will fix it once I have the code the way I want. Can anyone advise?

Unit Testing Solutions


Solution 1 - Unit Testing

If you want to skip running and compiling tests:

mvn -Dmaven.test.skip=true install

If you want to compile but not run tests:

mvn install -DskipTests

Solution 2 - Unit Testing

If you are using eclipse there is a "Skip Tests" checkbox on the configuration page.

> Run configurations → > Maven Build → > New → > Main tab → > Skip Tests Snip from eclipse

Solution 3 - Unit Testing

Run following command:

mvn clean install -DskipTests=true

Solution 4 - Unit Testing

With Intellij Toggle Skip Test Mode can be used from Maven Projects tab:

Solution 5 - Unit Testing

mvn clean install -Dskiptests=true   

Now, the only difference from the answers above is that the "T" is in lower case.

Solution 6 - Unit Testing

I like short version: mvn clean install -DskipTests

It's work too: mvn clean install -DskipTests=true

If you absolutely must, you can also use the maven.test.skip property to skip compiling the tests. maven.test.skip is honored by Surefire, Failsafe and the Compiler Plugin. mvn clean install -Dmaven.test.skip=true

and you can add config in maven.xml

<project>
      [...]
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.16</version>
            <configuration>
              <skipTests>true</skipTests>
            </configuration>
          </plugin>
        </plugins>
      </build>
      [...]
    </project>

Solution 7 - Unit Testing

If you call your classes tests Maven seems to run them automatically, at least they did for me. Rename the classes and Maven will just go through to verification without running them.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionFedererView Question on Stackoverflow
Solution 1 - Unit TestingalphazeroView Answer on Stackoverflow
Solution 2 - Unit TestingJStarkView Answer on Stackoverflow
Solution 3 - Unit TestingOhadRView Answer on Stackoverflow
Solution 4 - Unit TestingMujahid MasoodView Answer on Stackoverflow
Solution 5 - Unit TestingAggie Jon of 87View Answer on Stackoverflow
Solution 6 - Unit TestingGleb BelyaevView Answer on Stackoverflow
Solution 7 - Unit Testinguser6278062View Answer on Stackoverflow