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-06 13:28:20

โ–ถ 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-06 13:28:20
Time Zone: Europe/Berlin

Test Classes

4

Total Tests

12

Passed

12

Failed

0

Disabled

0

Aborted

0

Total Runtime

2.6s

Success Rate

100.0%

Available Processors

14

Spring Context Caching Statistics

Cache Size: 3 / 32
Cache Hits: 197
Cache Misses: 6
Cache Hit Rate: 97.0%

๐Ÿ” 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 247 beans
Load Time: 9ms
Heap Memory: 19.5MB
Test Classes: digital.pragmatech.demo.BadTwoIT
Context ID: context-1 248 beans
Load Time: 1ms
Heap Memory: 98.0MB
Test Classes: digital.pragmatech.demo.BadThreeIT
Context ID: context-2 242 beans
Load Time: 0ms
Heap Memory: 50.0MB
Test Classes: digital.pragmatech.demo.GoodIT
Context ID: context-3 247 beans
Load Time: 116ms
Heap Memory: 170.0MB
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(247)LocationsProperty Source PropertiesClassesContext Initializer ClassesActive ProfilesProperty Source LocationsContext CustomizersContext LoaderParentTest Context Bcontext-1Beans(248)LocationsProperty Source PropertiesClassesContext Initializer ClassesActive ProfilesProperty Source LocationsContext CustomizersContext LoaderParent

Property Source Properties - Detailed Comparison

Test Context A

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 B

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 A - Test Classes

  • BadTwoIT

Test Context B - Test Classes

  • BadThreeIT

โšก Build Time Optimization Recommendations

Potential Time Savings: 117ms (92.9% of total context load time)
Total Context Creation Time: 126ms
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.GoodIT digital.pragmatech.demo.GoodIT:unknown
The test class 'digital.pragmatech.demo.GoodIT' 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 @MockBean or @SpyBean instead of modifying application state โ€ข Move context-modifying operations to separate test classes โ€ข Use @Transactional with @Rollback for database operations โ€ข Consider using TestContainers for integration tests
@DirtiesContext detected (method-level on BigDecimal) MEDIUM
digital.pragmatech.demo.GoodIT BigDecimal:unknown
The test class 'digital.pragmatech.demo.GoodIT' 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 from individual methods โ€ข Use @MockBean or @SpyBean for method-specific mocking โ€ข Use @Transactional with @Rollback for database state changes โ€ข Refactor to avoid modifying shared application state โ€ข Group context-modifying tests into separate test classes
@DirtiesContext detected (class-level) HIGH
digital.pragmatech.demo.BadOneIT digital.pragmatech.demo.BadOneIT:30
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 @MockBean or @SpyBean instead of modifying application state โ€ข Move context-modifying operations to separate test classes โ€ข Use @Transactional with @Rollback for database operations โ€ข Consider using TestContainers for integration tests
@DirtiesContext detected (method-level on BigDecimal) MEDIUM
digital.pragmatech.demo.BadOneIT BigDecimal:unknown
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 from individual methods โ€ข Use @MockBean or @SpyBean for method-specific mocking โ€ข Use @Transactional with @Rollback for database state changes โ€ข Refactor to avoid modifying shared application state โ€ข Group context-modifying tests into separate test classes

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@5f9edf14, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@a8ef162, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.web.client.TestRestTemplateContextCustomizer@4ef74c30, org.springframework.boot.test.web.reactor.netty.DisableReactorResourceFactoryGlobalResourcesContextCustomizerFactory$DisableReactorResourceFactoryGlobalResourcesContextCustomizerCustomizer@747f281, org.springframework.boot.test.autoconfigure.OnFailureConditionReportContextCustomizerFactory$OnFailureConditionReportContextCustomizer@4808bc9b, 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@74f6c5d8, org.springframework.test.context.support.DynamicPropertiesContextCustomizer@0, org.springframework.boot.test.context.SpringBootTestAnnotation@ece01921]
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@5f9edf14, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@a8ef162, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.web.client.TestRestTemplateContextCustomizer@4ef74c30, org.springframework.boot.test.web.reactor.netty.DisableReactorResourceFactoryGlobalResourcesContextCustomizerFactory$DisableReactorResourceFactoryGlobalResourcesContextCustomizerCustomizer@747f281, org.springframework.boot.test.autoconfigure.OnFailureConditionReportContextCustomizerFactory$OnFailureConditionReportContextCustomizer@4808bc9b, 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@74f6c5d8, 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
248 beans
configurationClasses:
[DemoApplication]
activeProfiles:
[test]
contextLoader:
SpringBootContextLoader
properties:
6 properties
parentContext:
contextCustomizers:
[[ImportsContextCustomizer@70a8ebfc 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@5f9edf14, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@a8ef162, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.web.client.TestRestTemplateContextCustomizer@4ef74c30, org.springframework.boot.test.web.reactor.netty.DisableReactorResourceFactoryGlobalResourcesContextCustomizerFactory$DisableReactorResourceFactoryGlobalResourcesContextCustomizerCustomizer@747f281, org.springframework.boot.test.autoconfigure.OnFailureConditionReportContextCustomizerFactory$OnFailureConditionReportContextCustomizer@4808bc9b, 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@74f6c5d8, org.springframework.test.context.support.DynamicPropertiesContextCustomizer@0, org.springframework.boot.test.context.SpringBootTestAnnotation@ece01921]
locations:
contextInitializers:
[]
beanDefinitionCount:
248
Test classes using this configuration:
digital.pragmatech.demo.BadThreeIT
Context Complexity: 248 bean definitions
๐Ÿ”ง config-0
1 test class
247 beans
configurationClasses:
[DemoApplication]
activeProfiles:
[test, integration]
contextLoader:
SpringBootContextLoader
properties:
6 properties
parentContext:
contextCustomizers:
[org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@5f9edf14, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@a8ef162, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.web.client.TestRestTemplateContextCustomizer@4ef74c30, org.springframework.boot.test.web.reactor.netty.DisableReactorResourceFactoryGlobalResourcesContextCustomizerFactory$DisableReactorResourceFactoryGlobalResourcesContextCustomizerCustomizer@747f281, org.springframework.boot.test.autoconfigure.OnFailureConditionReportContextCustomizerFactory$OnFailureConditionReportContextCustomizer@4808bc9b, 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@74f6c5d8, 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

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.9s ๐Ÿ“Š 3 tests โœ… 3
โœ… testServiceCreateBook
2ms PASSED
โœ… testServiceFindByAuthor
301ms PASSED
โœ… testServiceCountByCategory
4ms PASSED
BadThreeIT
digital.pragmatech.demo
โฑ๏ธ 248ms ๐Ÿ“Š 3 tests โœ… 3
โœ… testGetBookCountViaRestApi
74ms PASSED
โœ… testGetAllBooksViaRestApi
7ms PASSED
โœ… testCreateBookViaRestApi
26ms PASSED
GoodIT
digital.pragmatech.demo
โฑ๏ธ 137ms ๐Ÿ“Š 3 tests โœ… 3
โœ… testRepositoryAndService
4ms PASSED
โœ… testContextReuseAgain
2ms PASSED
โœ… testAnotherOperationSameContext
3ms PASSED
BadOneIT
digital.pragmatech.demo
โฑ๏ธ 352ms ๐Ÿ“Š 3 tests โœ… 3
โœ… testCreateBook
1ms PASSED
โœ… testFindByCategory
15ms PASSED
โœ… testCountBooks
2ms PASSED