The Spring Test Profiler is a Spring Test utility that provides visualization and insights for Spring Test execution, with a focus on Spring context caching.
It helps you identify optimization opportunities in your Spring Test suite to speed up your builds and ship to production faster and with more confidence.
Find more information about the profiler on our website.
Overall goal: Identify optimization opportunities in your Spring Test suite to speed up your builds and ship to production faster and with more confidence 🚤
This profiler helps you:
- Track Spring Test context caching statistics for your test suite
- Show context reuse metrics and cache hit/miss ratios
- Identify tests that couldn't reuse contexts and explain why
- Easy integration with a
spring.factoriesfile or@TestExecutionListenersannotation - Works with both Maven Surefire/Failsafe and Gradle test tasks
This profiler works with Java 17+ and is compatible with Spring Framework 6 and 7 (aka. Spring Boot 3 and 4).
Warning
This project is highly work-in-progress and should be considered a prototype to gather feedback and ideas for future development.
What's currently not working or missing:
- Support for parallel test execution
- Fully-fledged visualization of the contexts on a timeline
- For each Gradle test task, a separate HTML report is generated
- For Surefire and Failsafe, a separate HTML report is generated
Add the dependency to your project:
<dependency>
<groupId>digital.pragmatech.testing</groupId>
<artifactId>spring-test-profiler</artifactId>
<version>0.0.15</version>
<scope>test</scope>
</dependency>
Add the dependency to your project:
testImplementation('digital.pragmatech.testing:spring-test-profiler:0.0.15')
Pick either one of the following methods to activate the profiler in your tests.
Add a file named META-INF/spring.factories to your resources directory with the following content:
org.springframework.test.context.TestExecutionListener=\
digital.pragmatech.testing.SpringTestProfilerListener
org.springframework.context.ApplicationContextInitializer=\
digital.pragmatech.testing.diagnostic.ContextDiagnosticApplicationInitializer
Add the @TestExecutionListeners and @ContextConfiguration annotations to your test classes:
@TestExecutionListeners(
value = {SpringTestProfilerListener.class},
mergeMode = TestExecutionListeners.MergeMode.MERGE_WITH_DEFAULTS
)
@ContextConfiguration(initializers = ContextDiagnosticApplicationInitializer.class)
This needs to be done for each test class where you want to use the profiler. Preferably, use this on a central abstract integration test class or use the automatic activation method above.
Execute your tests:
# Maven
./mvnw verify
# Gradle
./gradlew build
After test execution, find the HTML report at:
- Maven:
target/spring-test-profiler/latest.html - Gradle:
build/spring-test-profiler/latest.html
Access a demo Spring Test Profiler report here.
Found a bug? Please help us improve by reporting it:
- Search existing issues at https://github.com/PragmaTech-GmbH/spring-test-profiler/issues
- Create a new issue with:
- Clear description of the problem
- Steps to reproduce
- Expected vs actual behavior
- Java/Spring/JUnit versions
- Relevant log output or screenshots
We welcome contributions! Here's how to get started:
- Fork and clone the repository
- Activate pre-commit hooks (this ensures compliant code formatting):
pre-commit install(pre-commit download) - Build the project:
./mvnw install
- Run tests:
./mvnw test
- Use conventional commit messages for your changes (e.g.,
feat: add new feature,fix: resolve issue #123)


