Running Unit Tests With Maven

Jakob Jenkov
Last update: 2014-05-24

If you are using the build tool Apache Maven, Maven can run your unit tests for you. In fact, you pretty much get that for free when using Maven. If you don't know Maven, it's a build tool like Ant, but more ambitious in my opinion.

I am not going to tell you everything about Maven here. It's a very extensive tool. I will just quickly show you how to run the unit tests with Maven, so you know that it is a possibility.

When you build a project using Maven, the build process passes through a set of phases. One of these phases are called test. To execute the test phase, and all phases before it, you use the following Maven command:

mvn test    

That's pretty simple, isn't it? Of course, seing this command only makes sense if you know a little bit about how to set your code project up to use Maven. You can read more about that on the Maven site (see link above). Or, perhaps I will write about Maven in the future too.

Here is an example of the output from Maven:

Skipping the Tests

Maven always by default run your unit tests, if you run a mvn install which builds your project. Sometimes, however, you want to build it without running the unit tests. You can do so, like this:

mvn install -Dmaven.test.skip=true    

Jakob Jenkov

Featured Videos















Core Software Performance Optimization Principles




Advertisements

High-Performance
Java Persistence
Close TOC

All Trails

Trail TOC

Page TOC

Previous

Next