Maven Surefire Plugin

The Maven Surefire Plugin is used to run unit tests of an application. It generates reports in two different file formats:

  • Plain text files (*.txt)
  • XML files (*.xml)

Goals:

surefire:test runs the unit tests of an application.

Run the following command to run all unit tests in your project.

mvn test

Output:

[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ HelloWorld ---
[INFO] Surefire report directory: C:\projects\HelloWorldApplication\target\surefire-reports
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/surefire/surefire-junit4/2.12.4/surefire-junit4-2.12.4.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/surefire/surefire-junit4/2.12.4/surefire-junit4-2.12.4.pom (2.4 kB at 1.1 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/surefire/surefire-junit4/2.12.4/surefire-junit4-2.12.4.jar
Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/surefire/surefire-junit4/2.12.4/surefire-junit4-2.12.4.jar (37 kB at 34 kB/s)

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running HelloWorldTest
Hello World
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.133 sec

Results :

Tests run: 1, Failures: 0, Errors: 0, Skipped: 0

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  8.872 s
[INFO] Finished at: 2020-04-19T20:43:59+05:30
[INFO] ------------------------------------------------------------------------

 

Configuration:

1. Using Junit: The following configuration will run all unit tests in parallel in 10 different threads.

<build>
    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>3.0.0-M4</version>
        <configuration>
          <parallel>methods</parallel>
          <threadCount>10</threadCount>
        </configuration>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>

2. Skipping Tests: The following configuration will skip all tests for your project.

<build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>3.0.0-M4</version>
        <configuration>
          <skipTests>true</skipTests>
        </configuration>
      </plugin>
    </plugins>
  </build>

3. Inclusion/Exclusion of Tests: The following configuration will include/exclude tests for your project.

<build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>3.0.0-M4</version>
        <configuration>
          <includes>
            <include>ChromeTest.java</include>
          </includes>
          <excludes>
          <exclude>IETest.java</exclude>
          </excludes>
        </configuration>
      </plugin>
    </plugins>
  </build>

 

 

Share

Bijan Patel

Founder & Creator of QAScript | 12+ years of IT Experience | Full Stack Automation Engineer | Blogger | Trainer

You may also like...

2 Responses

  1. Errol Grade says:

    Hi there! I know this is somewhat off topic but I was wondering if you knew where I could locate a captcha plugin for my comment form? I’m using the same blog platform as yours and I’m having difficulty finding one? Thanks a lot!

Leave a Reply

Your email address will not be published. Required fields are marked *

error: Content is protected !!