How do you control which test classes Failsafe runs, and what are its default include patterns?
answer
- *IT, IT*, *ITCase defaults
- no overlap with Surefire *Test
- -Dit.test not -Dtest
- -DskipITs vs -DskipTests
- groups/excludedGroups = @Tag
basics
~10 sBy default Failsafe picks up classes matching IT, IT, and *ITCase. You override this with <includes>/<excludes> in the plugin config to match your own naming.
solid answer
~30 sFailsafe's default `<includes>` are `**/IT*.java`, `**/*IT.java`, and `**/*ITCase.java` — distinct from Surefire's `*Test` patterns so unit and integration tests are routed to the right plugin automatically. You override with `<includes>`/`<excludes>` in the plugin configuration if you use a different convention (say `*IntegrationTest`). You can also run a single class from the CLI with `-Dit.test=FooIT` (Failsafe's property is `it.test`, NOT Surefire's `test`). Other useful knobs: `<skipITs>` to skip only integration tests while keeping unit tests, `<groups>`/`<excludedGroups>` for JUnit tags/categories, and `<systemPropertyVariables>` to pass config into the test JVM.
code
bash · 2 linesmvn verify -Dit.test=OrderIT#shouldPlaceOrder
mvn verify -DskipITs # run unit tests, skip integration testsgo deeper
Knows *IT classes are integration tests by default.
Can override includes/excludes and use it.test and skip flags.
Uses tag-based grouping and property injection to shape suites.
Sets org-wide naming and skip conventions for unit/IT separation.
## Default selection Failsafe scans `target/test-classes` and selects, by default: - `**/IT*.java` - `**/*IT.java` - `**/*ITCase.java` This purposely does NOT overlap Surefire's defaults (`*Test`, `Test*`, `*Tests`, `*TestCase`), so a class named `OrderIT` runs as an integration test and `OrderTest` runs as a unit test, with no extra config. ## Overriding the patterns ```xml <plugin> <artifactId>maven-failsafe-plugin</artifactId> <version>3.2.5</version> <configuration> <includes> <include>**/*IntegrationTest.java</include> </includes> <excludes> <exclude>**/Abstract*.java</exclude> </excludes> </configuration> <executions> <execution><goals><goal>integration-test</goal><goal>verify</goal></goals></execution> </executions> </plugin> ``` ## CLI selection and skipping - Run one IT: `mvn verify -Dit.test=OrderIT` (note `it.test`, not `test`). - Run one method: `mvn verify -Dit.test=OrderIT#shouldPlaceOrder`. - Skip ITs only: `mvn verify -DskipITs` (unit tests still run). - Skip ALL tests including compilation: `-Dmaven.test.skip=true`; skip running but still compile: `-DskipTests`. ## Tag/category filtering ```xml <configuration> <groups>slow</groups> <excludedGroups>flaky</excludedGroups> </configuration> ``` With JUnit 5 these map to `@Tag` values. ## Passing configuration to tests ```xml <configuration> <systemPropertyVariables> <it.http.port>${it.http.port}</it.http.port> </systemPropertyVariables> </configuration> ``` These become `System.getProperty(...)` values inside the test JVM.
- What CLI property selects a single Failsafe test, and how does it differ from Surefire?Failsafe uses -Dit.test=ClassName; Surefire uses -Dtest=ClassName. They are separate so you can target unit vs integration tests independently.
- Difference between -DskipITs and -DskipTests?-DskipITs skips only integration (Failsafe) tests; -DskipTests skips both Surefire and Failsafe runs but still compiles test sources.
saying these in an interview costs you the question
- Thinking Failsafe and Surefire share the same default patterns.
- Using -Dtest to filter Failsafe (it's -Dit.test).
- Believing -DskipTests and -Dmaven.test.skip are equivalent (the latter also skips compiling tests).