Executing Unit Tests
Now that your project has unit tests, let’s run them. You don’t
have to do anything special to run a unit test; the
test phase is a normal part of the Maven lifecycle.
You run Maven tests whenever you run mvn
package or mvn install.
If you would like to run all the lifecycle phases up to and including
the test phase, run mvn
test:
$ mvn test
...
[INFO] [surefire:test]
[INFO] Surefire report directory: ~/examples/simple-weather/target/\
surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running org.sonatype.mavenbook.weather.yahoo.WeatherFormatterTest
0 INFO YahooParser - Creating XML Reader
177 INFO YahooParser - Parsing XML Response
239 INFO WeatherFormatter - Formatting Weather Data
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.547 sec
Running org.sonatype.mavenbook.weather.yahoo.YahooParserTest
475 INFO YahooParser - Creating XML Reader
483 INFO YahooParser - Parsing XML Response
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.018 sec
Results :
Tests run: 2, Failures: 0, Errors: 0, Skipped: 0
Executing mvn test from the
command line causes Maven to execute all lifecycle phases up to the
test phase. The Maven Surefire plugin has a test goal that is bound to the test phase. This test goal executes all of the unit tests
that this project can find under src/test/java. In the case of this project, you can see that the Surefire plugin’s ...