Appendix A. Automating Your Unit and Integration Tests

Automating Your Tests with Maven

Maven is a popular open source build tool of the Java world, that makes use of practices such as declarative dependencies, standard directories and build life cycles, and convention over configuration to encourage clean, maintainable, high level build scripts. Test automation is strongly supported in Maven. Maven projects use a standard directory structure: it will automatically look for unit tests in a directory called (by default) src/test/java. There is little else to configure: just add a dependency to the test framework (or frameworks) your tests are using, and Maven will automatically look for and execute the JUnit, TestNG, or even Plain Old Java Objects (POJO) tests contained in this directory structure.

In Maven, you run your unit tests by invoking the test life cycle phase, as shown here:

$ mvn test [INFO] Scanning for projects... [INFO] ------------------------------------------------------------------------ [INFO] Building Tweeter domain model [INFO] task-segment: [test] [INFO] ------------------------------------------------------------------------ ... ------------------------------------------------------- T E S T S ------------------------------------------------------- Running com.wakaleo.training.tweeter.domain.TagTest Tests run: 13, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.093 sec Running com.wakaleo.training.tweeter.domain.TweeterTest Tests run: 3, Failures: 0, Errors: ...

Get Jenkins: The Definitive Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.