What is the use of Maven-Surefire plugin

MavenMaven Surefire-Plugin

Maven Problem Overview


What is the use of the Maven Surefire Plugin? I can not find a proper example.

Maven Solutions


Solution 1 - Maven

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)

Solution 2 - Maven

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.

Solution 3 - Maven

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>

Solution 4 - Maven

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

Solution 5 - Maven

According to Apache the surefire plugin is for

> 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:

Apache Surefire Plugin

All yours unit tests that have an annotation of @test will be executed. But you can also use the plugin to add or exclude tests like such:

<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<configuration>
    <excludes>
        <exclude>DataTest.java</exclude>
    </excludes>
    <includes>
        <include>DataCheck.java</include>
    </includes>
</configuration>

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionprasannajitView Question on Stackoverflow
Solution 1 - MavenAmey JadiyeView Answer on Stackoverflow
Solution 2 - MavenfakirchandView Answer on Stackoverflow
Solution 3 - MavenPratik AmbaniView Answer on Stackoverflow
Solution 4 - MavenSDVView Answer on Stackoverflow
Solution 5 - Mavenuser13892443View Answer on Stackoverflow