What is the use of Maven-Surefire plugin

Better you start with https://maven.apache.org/surefire/maven-surefire-plugin/

In short link says:

The Surefire Plugin is used during the test phase of the build lifecycle to execute the unit tests of an application. It generates reports in two different file formats Plain text files (.txt) XML files (.xml)


Maven sure fire plugin is used to follow the sequence of tests in testng.xml file. If we don't include the Mavwen surefire plugin then it will execute all the testcases under src/test/java which has prefix or suffix as 'test' and these tests will get executed without any sequence.


Here you can find best description of what surefire is, and what role does it play in lifecycle of maven.

It is called implicitely by the maven lifecycle in the appropiate phase so it is a ‘special’ plugin. We don´t need to define it inside pom.xml it will be downloaded and executed when maven needs it.

It has only one goal inside it, and undoubtly it is "test", and defined by apache folks,

test: Allow us to run the unit tests of the application

Though, we can denote it inside pom.xml to run our unit tests of src/test/java folder.

<build>
    <plugins>
        <plugin>
            <artifactId>maven-jar-plugin</artifactId>
            <version>2.4</version>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.19</version>
        </plugin>
    </plugins>
</build>

maven-surefire-plugin which is used by default whenever test goal is executed [ with 'mvn test' / 'mvn install' e.g.]. You can configure this plugin in pom.xml to provide some configuration information like the location of test artifacts [testng.xml] or option to include the conditions(defining group, excluding groups, thread-count, parallelism and skip directly with plugin configuration in pom.xml. Thus you have the choice where to put that information(in pom.xml or in suite testng.xml)

earlier this was a great help when Junit lags parallel execution