EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 600+ Courses All in One Bundle
  • Login

Maven Failsafe Plugin

Secondary Sidebar
Maven Tutorial
  • Maven Basic and advance
    • What is Maven
    • How to Install Maven
    • Maven Commands
    • Maven GroupId
    • Maven WAR Plugin
    • Maven Build Command
    • Maven Failsafe Plugin
    • Maven Profile
    • IntelliJ Maven
    • Maven Enforcer Plugin
    • Maven Javadoc Plugin
    • Maven WAR Plugin
    • Maven Build Command
    • Maven GroupId
    • Maven Force Update
    • Maven Encrypt Password
    • Maven Environment Variables
    • AssertJ Maven
    • Maven Run Single Test
    • Maven kafka-clients
    • Maven Quickstart Archetype
    • Maven Install Dependencies
    • Maven XMLBeans
    • Maven Local Repository
    • Maven Versions
    • Maven Jar Plugin
    • Maven Assembly Plugin
    • Maven exec plugin
    • Maven Central Repository
    • Maven Surefire
    • Maven Deploy
    • Maven Phases
    • Maven Archetype
    • Maven Skip Test
    • Maven Dependency Scope
    • Maven Shade Plugin
    • Maven Repository Spring
    • Maven Eclipse Plugin
    • Maven Exclude Dependency
    • Maven Life Cycle
    • Maven Repository
    • Maven POM File
    • Maven Plugins
    • What is Maven Plugins
    • Maven Interview Questions
    • Maven Flags
    • Maven Project
    • Maven Settings.XML
Home Software Development Software Development Tutorials Maven Tutorial Maven Failsafe Plugin

Maven Failsafe Plugin

Introduction to Maven Failsafe Plugin

Maven failsafe plugin is a part of maven plugins used for running the integration test of our maven project. The failsafe plugin is similar to the plugin of maven surefire. The failsafe plugin is used in the integration tests, whereas the surefire plugin runs the unit test for the project. The failsafe plugin is very important when doing integration testing.

All in One Software Development Bundle(600+ Courses, 50+ projects)
Python TutorialC SharpJavaJavaScript
C Plus PlusSoftware TestingSQLKali Linux
Price
View Courses
600+ Online Courses | 50+ projects | 3000+ Hours | Verifiable Certificates | Lifetime Access
4.6 (86,064 ratings)

Overview of Maven Failsafe Plugin

When running the integration test, the lifecycle will contain the same four phases. Below are the lifecycle phases for running the integration tests as follows.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

  • The first phase is the pre-integration test, which was used to set up the integration test environment.
  • The second phase of the life cycle of the integration test is the integration test used to run the integration testing.
  • The third phase of the life cycle of the integration test is a post-integration test used to tear down the environment of the integration test.
  • The fourth phase of the life cycle of the integration test verifies the integration test, which was used to check the result of integration tests.

The maven plugin of failsafe creates the reports into two different file formats, i.e., failsafe integration tests are running on integration tests for a specific application. Failsafe verify will verify the integration test from which the application is passed.

Key Takeaways

  • The failsafe plugin runs the method onto the test classes like the surefire plugin. A failsafe plugin is used to do the integration test.
  • The goal of the failsafe plugin is the integration test, which was bound to the integration test phase by default.

How to Use Maven Failsafe Plugin?

We must create the project template into the spring tool suite to use the failsafe plugins. The below steps show how we can use the failsafe plugin.

  • In this step, we are creating the project template of the failsafe plugin into the spring initializer. We are giving the name of the maven project as maven_failsafe. We are defining the packaging as jar and selecting the java version as 8.

Group name – com.example              Artifact – maven_failsafe

Name – maven_failsafe                      Packaging – jar

Java version – 8

Use Maven Failsafe Plugin 1

  • After creating the template of maven failsafe, now in this step, we are opening the failsafe plugin project into the spring tool suite as follows.

Use Maven Failsafe Plugin 2

  • After opening the project template of the failsafe plugin in this step we are checking the project structure and files.

Use Maven Failsafe Plugin 3

  • After opening the project now in this step we are adding the failsafe plugin into the pom.xml file as follows.

Code:

<plugin>
<artifactId> maven-failsafe-plugin </artifactId>
<version> 3.0.0-M5 </version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>

Use Maven Failsafe Plugin 4

  • After adding the plugin into the pom.xml file now in this we are building the project through GUI as follows.

Use Maven Failsafe Plugin 5

Maven Failsafe Run

The failsafe plugin is used to run the test. In the example below, we are configuring the jetty server to start the integration test and stop the same after the test execution. To start the integration tests first, we need to add the plugin of a jetty server into the pom.xml file. In the example below, we are first adding the code below into the pom.xml file. In the below example, we are defining the plugin directive.

Code:

<plugin>
<groupId> org.eclipse.jetty </groupId>
<artifactId> maven-plugin </artifactId>
<version> 9.4.11.v20180605 </version>
<executions>
<execution>
<id> start </id>
<phase> integration test </phase>
<goals>
<goal> start </goal>
</goals>
</execution>
<execution>
<id> stop </id>
<phase> post test </phase>
<goals>
<goal> stop </goal>
</goals>
</execution>
</executions>
</plugin>

Maven Failsafe Run 1

After adding the plugin of a jetty, below we are running the integration test on the jetty plugin as follows. In the above example, we added the configuration to start and stop the jetty server at the time of the integration test.  In the below example, we are executing the test and checking the result from the console. In the below example we can see that we have run the integration test on the jetty plugin. For using the different plugins for different tests it is nothing but the separation between configurations.

Maven Failsafe Run 2

Setting up Maven Failsafe Plugin

At the time of setting up the failsafe plugin first, we need to configure the failsafe plugin into the pom.xml file. All the plugins we are adding to the project need to be added to the pom.xml file. We are setting up the below configuration into the pom.xml file. We are defining the artifact id as “maven failsafe setting,” then we are defining the version of configuration as 3.0.0. Also, we are defining the goal as an integration test and verifying it as follows.

Code:

<plugin>
<artifactId> maven-plugin </artifactId>
<version>3.0.0-M5</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>

Setting up 1

After setting up the failsafe configuration now we are running the integration test and building the configuration of the failsafe plugin as follows.

Setting up 2

Maven Failsafe Plugin Exclusion

The failsafe plugin runs on the test classes of the surefire plugin. We are configuring the surefire and failsafe plugins similarly. The failsafe plugin’s goal will be to specify in the pom.xml file. The below example shows failsafe plugin execution as follows. In the below example, we are defining the integration test as follows.

Code:

<plugin>
<artifactId> maven-failsafe </artifactId>
<version> 2.21.0 </version>
<executions>
<execution>
<goals>
<goal> test </goal>
</goals>
<configuration>
</configuration>
</execution>
</executions>
</plugin>

Exclusion 1

After defining the exclusion of the maven failsafe plugin below example we are loading the failsafe plugin as follows.

Exclusion 2

FAQ

Given below are the FAQs mentioned:

Q1. What is the use of the failsafe plugin a maven application?

Answer: We are using the failsafe plugin to do the integration test of the maven project. It works similarly to the surefire plugin.

Q2. How many goals are defined in failsafe plugin?

Answer: There are two types of goals defined in the failsafe plugin i.e. verify and the integration test.

Q3. Can we use a jetty server to run the integration test by using the failsafe plugin?

Answer: To run the integration test of the project we are using a jetty server to run the test of the maven application.

Conclusion

When running the integration test, the lifecycle contains the four phases of the maven failsafe plugin. Maven failsafe plugin is a part of plugins used to run integration tests of our project. The maven failsafe plugin is similar to the plugin of maven surefire.

Recommended Articles

This is a guide to Maven Failsafe Plugin. Here we discuss the introduction and how to use Maven Failsafe Plugin to run, setting up, and exclusion. You may also have a look at the following articles to learn more –

  1. Maven Surefire
  2. Maven Plugins
  3. Maven Skip Test
  4. What is Maven Plugins?
Popular Course in this category
Maven Training (4 Courses, 6 Projects)
  4 Online Courses |  6 Hands-on Project |  26+ Hours |  Verifiable Certificate of Completion
4.5
Price

View Course
0 Shares
Share
Tweet
Share
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Java Tutorials
  • Python Tutorials
  • All Tutorials
Certification Courses
  • All Courses
  • Software Development Course - All in One Bundle
  • Become a Python Developer
  • Java Course
  • Become a Selenium Automation Tester
  • Become an IoT Developer
  • ASP.NET Course
  • VB.NET Course
  • PHP Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2022 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA
Free Software Development Course

C# Programming, Conditional Constructs, Loops, Arrays, OOPS Concept

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

Special Offer - Maven Training (4 Courses, 6 Projects) Learn More