10 Running JUnit tests from Maven 3

 

This chapter covers

  • Creating a Maven project from scratch
  • Testing the Maven project with JUnit 5
  • Using Maven plugins
  • Using the Maven Surefire plugin

The conventional view serves to protect us from the painful job of thinking.

--John Kenneth Galbraith

This chapter discusses a common build system tool called Maven. In the previous chapters, with provided Maven projects, you needed only to look at some external dependencies, run some simple commands, or run the tests from inside the IDE. This chapter gives you a brief introduction to the Maven build system, which will be very useful if you need a systematic way to start your tests.

Maven addresses two aspects of building software. First, it describes how software is built; then, it describes the needed dependencies. Unlike earlier tools, such as Apache Ant, it uses conventions for the build procedure, and only exceptions need to be written down. It relies on an XML file to describe its full configuration--most important are the meta-information about the software project being built, the needed dependencies on other external components, and the required plugins.

By the end of this chapter, you will know how to build Java projects with Maven, including managing their dependencies, executing JUnit tests, and generating JUnit reports. For basic Maven concepts and how to set up Maven, see appendix A.

10.1 Setting up a Maven project

10.2 Using the Maven plugins

10.2.1 Maven compiler plugin

10.2.2 Maven Surefire plugin

10.2.3 Generating HTML JUnit reports with Maven

10.3 Putting it all together

10.4 Maven challenges

Summary