Monthly Archives: May 2013

Skipping tests when doing “mvn install”

First things first: you should NOT be skipping tests when building your projects. 9 out of 10 cases, you shouldn’t. But when you must / have to / want to do it: after spiking what it looked like a quick solution to a little problem and it turned out to be a massive refactoring during which you broke so many tests it would not be worthy to fix them unless the original problem is really flushed away… possibly the most typical scenario where you would want to do something like this. Well, in that case, you can do:

mvn -DskipTests=true install

or the more lazy version:

mvn -DskipTests install

Or you can do:

mvn -Dmaven.skip.test=true install

or the more lazy version:

mvn -Dmaven.skip.test install

Difference between the first and the second is that the first one is less horrible. Let me explain… both versions will not run any of your tests classes, but at least the first one won’t succeed if they don’t compile. So, if you’ve broken your tests but at least you changed your source code well enough to maintain compilation errors away on your test classes, you can get away with the first command. But if you incurred in compilation errors on your test classes while changing your code, you may want to go for the second command, which not only it will ignore your tests but it won’t even attempt to compile the test classes.

If having to run the first command is already a sign that you’ve not been doing the important things (TDD, for instance) right, running the second means you can’t even use your IDE correctly (refactoring, anyone?).

[Learnt at work, from a colleague]

[Reference]