How to integration test auto configuration for a custom Spring Boot style starter library?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
When you build a custom Spring Boot starter, the important question is not just whether the configuration class compiles. The real question is whether a consumer application gets the right beans, conditions, and properties when the starter is placed on the classpath. That is why auto-configuration tests should exercise the starter the way Boot will actually wire it.
Use ApplicationContextRunner as the Default Test Tool
For starter libraries, ApplicationContextRunner is usually the best testing entry point. It boots a minimal application context, applies your auto-configuration, and lets you make assertions without starting a full app.
Suppose you have an auto-configuration class like this:
A focused test can look like this:
This style is fast, deterministic, and close to how Boot evaluates conditions.
Test Conditional Behavior Explicitly
Starter libraries often depend on conditions such as:
- classpath presence
- missing bean conditions
- property flags
- web application type
Each condition should have its own test. For example, if your starter should back off when the dependency class is missing, use FilteredClassLoader.
This is the sort of test that catches real starter regressions.
Verify Bean Backoff and User Overrides
A custom starter should usually not force its bean into the context when the application already defines one. Test that explicitly.
That test matters because @ConditionalOnMissingBean is one of the main promises of a well-behaved starter.
Use @SpringBootTest Sparingly
Full @SpringBootTest integration tests still have value, but they should be the minority. Use them when you need to prove that the starter works in a realistic application context with extra infrastructure, not for every small condition.
A full test might be appropriate when:
- the starter integrates with web infrastructure
- you need real environment binding
- you want to check interaction across multiple auto-configurations
For most starter logic, ApplicationContextRunner is the sharper tool.
Test Registration Metadata Too
Auto-configuration is only useful if Spring Boot can discover it. For Boot 3.x, that usually means the class is listed in META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports. Older Boot versions used spring.factories.
A very practical test strategy is to include at least one smoke test in a sample consumer module that depends on the built starter and boots a tiny application. That catches registration mistakes that pure unit-style context tests may miss.
Common Pitfalls
- Using only
@SpringBootTestmakes starter tests slower and less precise than necessary.ApplicationContextRunneris usually the better default. - Testing only the happy path misses the real value of starter tests, which is verifying conditional behavior and bean backoff.
- Forgetting to test the missing-classpath case can leave a starter failing in consumers that do not include an optional dependency.
- Assuming the auto-configuration is discoverable without verifying registration metadata can hide packaging mistakes until runtime.
- Asserting only that the context starts, without checking bean contents or bound properties, creates weak tests that miss configuration regressions.
Summary
- Test starter auto-configuration the way Boot actually evaluates it, not just by calling configuration code directly.
- Use
ApplicationContextRunnerfor most tests because it is fast and purpose-built for auto-configuration. - Cover classpath conditions, property conditions, and
@ConditionalOnMissingBeanbackoff explicitly. - Keep a small number of higher-level smoke tests for discovery and packaging confidence.
- Treat starter testing as contract testing for consumer applications, not just internal unit coverage.

