Book Image

Apache Maven Cookbook

By : Raghuram Bharathan
Book Image

Apache Maven Cookbook

By: Raghuram Bharathan

Overview of this book

If you are a Java developer or a manager who has experience with Apache Maven and want to extend your knowledge, then this is the ideal book for you. Apache Maven Cookbook is for those who want to learn how Apache Maven can be used for build automation. It is also meant for those familiar with Apache Maven, but want to understand the finer nuances of Maven and solve specific problems.
Table of Contents (13 chapters)
12
Index

Using the Maven Surefire plugin to run unit tests


A best practice of software development is writing automated unit tests for the code that you develop. Let us now see how to run these tests.

The plugin that does this job is the Maven Surefire plugin.

How to do it...

To run unit tests using the Maven Surefire plugin, perform the following steps:

  1. Open the command prompt.

  2. Run the following command on one of our sample projects:

    mvn test
    
  3. Observe the various steps that get executed:

    [INFO] --- maven-surefire-plugin:2.10:test (default-test) @ simple-project ---
    [INFO] Surefire report directory: C:\projects\apache-maven-cookbook\simple-project\target\surefire-reports
    -------------------------------------------------------
     T E S T S
    -------------------------------------------------------
    Running com.packt.cookbook.AppTest
    Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0 sec
    Results:
    Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
    

How it works...

The test parameter indicates the invocation...