Loading published curriculum…

06 · Maven from first build to release / LESSON 24 OF 102

Surefire, Failsafe, and test naming

A green build means little if your tests were never discovered.

Before this lesson: Build plugins, compiler release, and reproducibility

Understand the topic

Surefire normally runs unit tests during test. Failsafe separates integration-test execution from verification so cleanup phases can run before the build is failed. Test naming patterns determine which classes are discovered.

Configure Failsafe integration-test and verify goals if using *IT classes. Keep its version aligned with Surefire through project management. Review reports under target, including test counts, instead of relying only on BUILD SUCCESS.

EXAMPLE · XML

pom.xml build/plugins fragment

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-failsafe-plugin</artifactId>
  <executions><execution><goals>
    <goal>integration-test</goal><goal>verify</goal>
  </goals></execution></executions>
</plugin>

What to expect

With a managed plugin version, verify discovers conventional *IT integration tests and checks their results.

YOUR TURN

Put it into practice

  1. 01Add one passing unit test and one deliberately failing integration test.
  2. 02Compare test with verify and inspect both report directories.
  3. 03Verify: The integration failure fails verify and both suites report nonzero executed tests.

Pass a quiz or complete a lab to check today’s streak. Each lesson counts once per day, including when you review it later.

UNDER THE HOOD

Build the mental model

A green build means little if your tests were never discovered.

  1. 01Surefire normally runs unit tests during test. Failsafe separates integration-test execution from verification so cleanup phases can run before the build is failed. Test naming patterns determine which classes are discovered.
  2. 02Configure Failsafe integration-test and verify goals if using *IT classes. Keep its version aligned with Surefire through project management. Review reports under target, including test counts, instead of relying only on BUILD SUCCESS.
  3. 03Trace the example: With a managed plugin version, verify discovers conventional *IT integration tests and checks their results.

A mistake worth avoiding

An integration test is never executed.

DEBUGGING ROOM

Something broke. Where do you look?

An integration test is never executed.

Before revealing the diagnosis, write down your first investigation step.

CHECK YOUR UNDERSTANDING

Which command should check configured integration-test results?

Choose one answer

BUILD IT YOURSELF

Add one passing unit test and one deliberately failing integration test.

  1. 1.Add one passing unit test and one deliberately failing integration test.
  2. 2.Compare test with verify and inspect both report directories.
  3. 3.Reproduce this failure, then repair it: An integration test is never executed.

Acceptance checklist

Lab completion is your self-report. Knowledge checks do not certify project quality.

RETRIEVE IT FROM MEMORY

Which command should check configured integration-test results?

Revisit this lesson in three days after a successful check or lab.

Ready for the next step?

The integration failure fails verify and both suites report nonzero executed tests.

Reading is separate from passing a knowledge check or completing a lab.

Go deeper · official references