Maven package/install without test (skip tests)
If you want to execute a Maven build without running tests, use -DskipTests
. If you prefer to avoid compiling tests too, utilize -Dmaven.test.skip=true
. Choose your command according to your specific needs:
mvn install -DskipTests
mvn install -Dmaven.test.skip=true
The first command ignores test execution, while the second one skips both test compilation and execution.
Say no to tests via the Surefire plugin
You're not chained to the command line! You can also set a preference in your pom.xml
. Just add a skipTests
setting in your maven-surefire-plugin
configuration:
And just like a loyal dog, your build will faithfully skip tests every time without needing command-line instructions!
PowerShell pitfall and the backtick rescue mission
For the intrepid PowerShell users squeezing out every bit of Windows, you might face an obstacle with the special characters. The solution is as simple as adding a backtick before the Maven command (our very own
` in disguise! 🕵️♂️):
mvn install `-DskipTests
This quirky behavior of PowerShell is discussed in more detail here. Read to avoid a potential gotcha!
Beware, test skipper!
Let's not forget! Skipping tests might make your pipeline faster, especially when tests affect database content or are time-consuming. However, this habit may permit undetected bugs to creep unnoticed. Over time, your project's quality may decline. Use test-skipping judiciously, and always aim to maintain a strong continuous testing foundation in your development lifecycle.
Choose wisely – to skip or not to skip
Under certain conditions, like when applying trivial changes or during a hotfix deployment, skipping tests might be a practical choice. However, remember always to consider the context and implications of your decision.
Consider the trade-offs
Each time you bypass tests, remember that you're trading the assurance of quality for speed. Strive to balance expedience and risk, understanding the trade-offs in each decision.
Maven build profiles: The world beyond tests
Advanced projects can greatly benefit from Maven’s build profiles, allowing you to manage different scenarios such as development, testing, and production. For complex project setups, profiles can be meticulously tailored to conditionally skip tests, offering superior control over the entire build process.
Was this article helpful?