Spring Test Profiler Report

Understanding when and how many Spring ApplicationContexts are created in your test suite allows you to optimize build times by leveraging Spring TestContext's context caching feature, which reuses already started contexts.


Generated at: 2025-08-14 15:34:39

โ–ถ Understanding Spring TestContext Context Caching

Click to learn about Spring TestContext context caching principles and optimization tips

Test Execution Summary

Executed via: maven
Execution Time: 2025-08-14 15:34:39
Time Zone: Europe/Berlin

Test Classes

4

Total Tests

12

Passed

12

Failed

0

Disabled

0

Aborted

0

Total Runtime

2.7s

Success Rate

100.0%

Available Processors

14

Spring Context Caching Statistics

Cache Size: 3 / 32
Cache Hits: 196
Cache Misses: 7
Cache Hit Rate: 96.6%

๐Ÿ” Find Context by Test Class

Start typing to search for test classes. Results will appear after entering 3 or more characters.

Context Cache Entries

Context ID: context-0 248 beans
Load Time: 1ms
Heap Memory: 127.4MB
Test Classes: digital.pragmatech.demo.BadThreeIT
Context ID: context-1 247 beans
Load Time: 8ms
Heap Memory: 19.5MB
Test Classes: digital.pragmatech.demo.BadTwoIT
Context ID: context-2 242 beans
Load Time: 0ms
Heap Memory: 87.4MB
Test Classes: digital.pragmatech.demo.GoodIT
Context ID: context-3 247 beans
Load Time: 101ms
Heap Memory: 90.5MB
Test Classes: digital.pragmatech.demo.BadOneIT

๐Ÿ” Spring Test Context Visualizer

vs.
Same Configuration
Different Values
Spring Test Context ComparisonClick on any attribute circle (green/red) around the contexts below to see detailed differences.Test Context Acontext-0Beans(248)LocationsProperty Source PropertiesClassesContext Initializer ClassesActive ProfilesProperty Source LocationsContext CustomizersContext LoaderParentTest Context Bcontext-1Beans(247)LocationsProperty Source PropertiesClassesContext Initializer ClassesActive ProfilesProperty Source LocationsContext CustomizersContext LoaderParent

Property Source Properties - Detailed Comparison

Test Context A

Property Source Properties
spring.datasource.url=jdbc:h2:mem:badtest3;DB_CLOSE_DELAY=-1
spring.jpa.hibernate.ddl-auto=create-drop
server.servlet.context-path=/api/v1
spring.jackson.property-naming-strategy=SNAKE_CASE
org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true
server.port=0
โœ— Different from other context

Test Context B

Property Source Properties
server.port=8081
spring.datasource.url=jdbc:h2:mem:badtest2;DB_CLOSE_DELAY=-1
spring.jpa.hibernate.ddl-auto=create-drop
spring.jpa.show-sql=true
management.endpoints.web.exposure.include=health,info
org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true
โœ— Different from other context

Test Context A - Test Classes

  • BadThreeIT

Test Context B - Test Classes

  • BadTwoIT

โšก Build Time Optimization Recommendations

(this feature is highly work in progress)

Potential Time Savings: 102ms (92.7% of total context load time)
Total Context Creation Time: 110ms
Potentially Wasted Time: 0ms
Unique Contexts Created: 4

๐Ÿ’ก Optimization Tips

๐Ÿ”„

Harmonize Test Contexts

Reduce context variations by standardizing test configurations, profiles, and component scanning paths across similar test classes.

๐ŸŽฏ

Use Slice Tests

Replace @SpringBootTest with slice tests like @WebMvcTest, @DataJpaTest when testing specific layers.

โš™๏ธ

Optimize Component Scanning

Limit component scanning scope using @ComponentScan(basePackages) or exclude unnecessary configurations.

๐Ÿงช

Share Test Configuration

Create common @TestConfiguration classes that can be reused across multiple test classes.

๐Ÿ” Static Analysis Recommendations

Code analysis identified potential issues that may impact Spring context caching and test performance.

@DirtiesContext detected (class-level) HIGH
digital.pragmatech.demo.BadOneIT digital.pragmatech.demo.BadOneIT:class-level
The test class 'digital.pragmatech.demo.BadOneIT' uses @DirtiesContext which prevents Spring context caching. This forces Spring to recreate the application context for each test, significantly increasing test execution time.

๐Ÿ’ก Recommendation:

Consider the following alternatives: โ€ข Remove @DirtiesContext and redesign tests to be more isolated โ€ข Use @MockitoBean instead of modifying application state โ€ข Move context-modifying operations to separate test classes โ€ข Use @Transactional with @Rollback for database operations

Spring Context Configurations

This section shows all unique Spring context configurations detected during test execution, grouped by their MergedContextConfiguration.


๐Ÿ”ง config-3
1 test class
247 beans
configurationClasses:
[DemoApplication]
activeProfiles:
[test]
contextLoader:
SpringBootContextLoader
properties:
5 properties
parentContext:
contextCustomizers:
[org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@68746f22, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@2eea88a1, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.web.client.TestRestTemplateContextCustomizer@7283d3eb, org.springframework.boot.test.web.reactor.netty.DisableReactorResourceFactoryGlobalResourcesContextCustomizerFactory$DisableReactorResourceFactoryGlobalResourcesContextCustomizerCustomizer@1169afe1, org.springframework.boot.test.autoconfigure.OnFailureConditionReportContextCustomizerFactory$OnFailureConditionReportContextCustomizer@70e38ce1, org.springframework.boot.test.autoconfigure.actuate.observability.ObservabilityContextCustomizerFactory$DisableObservabilityContextCustomizer@1f, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@0, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizer@27912e3, org.springframework.test.context.support.DynamicPropertiesContextCustomizer@0, org.springframework.boot.test.context.SpringBootTestAnnotation@c673baa8]
locations:
contextInitializers:
[]
beanDefinitionCount:
247
Test classes using this configuration:
digital.pragmatech.demo.BadOneIT
Context Complexity: 247 bean definitions
๐Ÿ”ง config-2
1 test class
242 beans
configurationClasses:
[DemoApplication]
activeProfiles:
[test]
contextLoader:
SpringBootContextLoader
properties:
1 properties
parentContext:
contextCustomizers:
[org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@68746f22, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@2eea88a1, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.web.client.TestRestTemplateContextCustomizer@7283d3eb, org.springframework.boot.test.web.reactor.netty.DisableReactorResourceFactoryGlobalResourcesContextCustomizerFactory$DisableReactorResourceFactoryGlobalResourcesContextCustomizerCustomizer@1169afe1, org.springframework.boot.test.autoconfigure.OnFailureConditionReportContextCustomizerFactory$OnFailureConditionReportContextCustomizer@70e38ce1, org.springframework.boot.test.autoconfigure.actuate.observability.ObservabilityContextCustomizerFactory$DisableObservabilityContextCustomizer@1f, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@0, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizer@27912e3, org.springframework.test.context.support.DynamicPropertiesContextCustomizer@0, org.springframework.boot.test.context.SpringBootTestAnnotation@f232491a]
locations:
contextInitializers:
[]
beanDefinitionCount:
242
Test classes using this configuration:
digital.pragmatech.demo.GoodIT
Context Complexity: 242 bean definitions
๐Ÿ”ง config-1
1 test class
247 beans
configurationClasses:
[DemoApplication]
activeProfiles:
[test, integration]
contextLoader:
SpringBootContextLoader
properties:
6 properties
parentContext:
contextCustomizers:
[org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@68746f22, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@2eea88a1, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.web.client.TestRestTemplateContextCustomizer@7283d3eb, org.springframework.boot.test.web.reactor.netty.DisableReactorResourceFactoryGlobalResourcesContextCustomizerFactory$DisableReactorResourceFactoryGlobalResourcesContextCustomizerCustomizer@1169afe1, org.springframework.boot.test.autoconfigure.OnFailureConditionReportContextCustomizerFactory$OnFailureConditionReportContextCustomizer@70e38ce1, org.springframework.boot.test.autoconfigure.actuate.observability.ObservabilityContextCustomizerFactory$DisableObservabilityContextCustomizer@1f, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@0, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizer@27912e3, org.springframework.test.context.support.DynamicPropertiesContextCustomizer@0, org.springframework.boot.test.context.SpringBootTestAnnotation@e094b0af]
locations:
contextInitializers:
[]
beanDefinitionCount:
247
Test classes using this configuration:
digital.pragmatech.demo.BadTwoIT
Context Complexity: 247 bean definitions
๐Ÿ”ง config-0
1 test class
248 beans
configurationClasses:
[DemoApplication]
activeProfiles:
[test]
contextLoader:
SpringBootContextLoader
properties:
6 properties
parentContext:
contextCustomizers:
[[ImportsContextCustomizer@3c02b068 key = [org.springframework.boot.autoconfigure.task.TaskExecutionAutoConfiguration, org.springframework.boot.autoconfigure.web.servlet.HttpEncodingAutoConfiguration, org.springframework.boot.autoconfigure.validation.ValidationAutoConfiguration, org.springframework.boot.autoconfigure.context.MessageSourceAutoConfiguration, org.springframework.boot.autoconfigure.hateoas.HypermediaAutoConfiguration, org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration, org.springframework.boot.autoconfigure.data.web.SpringDataWebAutoConfiguration, org.springframework.boot.autoconfigure.thymeleaf.ThymeleafAutoConfiguration, org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration, org.springframework.boot.autoconfigure.gson.GsonAutoConfiguration, org.springframework.boot.autoconfigure.jsonb.JsonbAutoConfiguration, org.springframework.boot.autoconfigure.freemarker.FreeMarkerAutoConfiguration, org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration, org.springframework.boot.autoconfigure.http.HttpMessageConvertersAutoConfiguration, org.springframework.boot.autoconfigure.groovy.template.GroovyTemplateAutoConfiguration, org.springframework.boot.autoconfigure.mustache.MustacheAutoConfiguration]], org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@68746f22, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@2eea88a1, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.web.client.TestRestTemplateContextCustomizer@7283d3eb, org.springframework.boot.test.web.reactor.netty.DisableReactorResourceFactoryGlobalResourcesContextCustomizerFactory$DisableReactorResourceFactoryGlobalResourcesContextCustomizerCustomizer@1169afe1, org.springframework.boot.test.autoconfigure.OnFailureConditionReportContextCustomizerFactory$OnFailureConditionReportContextCustomizer@70e38ce1, org.springframework.boot.test.autoconfigure.actuate.observability.ObservabilityContextCustomizerFactory$DisableObservabilityContextCustomizer@1f, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@0, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizer@27912e3, org.springframework.test.context.support.DynamicPropertiesContextCustomizer@0, org.springframework.boot.test.context.SpringBootTestAnnotation@c673baa8]
locations:
contextInitializers:
[]
beanDefinitionCount:
248
Test classes using this configuration:
digital.pragmatech.demo.BadThreeIT
Context Complexity: 248 bean definitions

Test Execution Details

Click on any test class below to expand and see detailed information about individual test methods, including execution times and failure details.

BadTwoIT
digital.pragmatech.demo
โฑ๏ธ 1.8s ๐Ÿ“Š 3 tests โœ… 3
โœ… testServiceCreateBook
1ms PASSED
โœ… testServiceFindByAuthor
311ms PASSED
โœ… testServiceCountByCategory
5ms PASSED
BadThreeIT
digital.pragmatech.demo
โฑ๏ธ 400ms ๐Ÿ“Š 3 tests โœ… 3
โœ… testGetBookCountViaRestApi
69ms PASSED
โœ… testGetAllBooksViaRestApi
7ms PASSED
โœ… testCreateBookViaRestApi
26ms PASSED
GoodIT
digital.pragmatech.demo
โฑ๏ธ 158ms ๐Ÿ“Š 3 tests โœ… 3
โœ… testRepositoryAndService
4ms PASSED
โœ… testContextReuseAgain
2ms PASSED
โœ… testAnotherOperationSameContext
3ms PASSED
BadOneIT
digital.pragmatech.demo
โฑ๏ธ 326ms ๐Ÿ“Š 3 tests โœ… 3
โœ… testCreateBook
1ms PASSED
โœ… testFindByCategory
16ms PASSED
โœ… testCountBooks
3ms PASSED