What is the difference between Maven Surefire and Failsafe plugins?
Options
- They are the same plugin under two different names
- Surefire runs unit tests (
*Test); Failsafe runs*IT(Correct option) - Surefire builds Docker images for the application
- Failsafe only works on Windows machines and servers
Answer
Surefire runs unit tests in the test phase (*Test); Failsafe runs integration tests in integration-test/verify (*IT) so a failure does not leave resources half-cleaned
Why
Plugins do the real work in each Maven phase.
- maven-surefire-plugin: runs unit tests during
test(classes named*Test). - maven-failsafe-plugin: runs integration tests (classes named
*IT) duringintegration-test, and checks results inverify. This separation lets Maven shut down external things (like a test server) before reporting failure.
This split keeps mvn test fast.
Remember
Surefire = unit tests. Failsafe = integration tests.