Ninja-Squad/springmockk

Spring Boot reloads context when using clearMocks()

pzapasni opened this issue · 3 comments

After updating from 2.0.1 to 2.0.2, Spring Boot context is reloaded when test execution switches from executing one test class to another, and the two classes share a common superclass which uses clearMocks() method in an @AfterEach method. It's hard for me to describe this properly in text, so I've created a reproduction repo: https://github.com/pzapasni/springmockk-bug

When you run the tests with ./gradlew test, this is the output that you will get when using 2.0.2:

$ ./gradlew test

> Task :test

TestOne STANDARD_OUT
    12:46:45.096 [Test worker] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating CacheAwareContextLoaderDelegate from class [org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate]
    12:46:45.107 [Test worker] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating BootstrapContext using constructor [public org.springframework.test.context.support.DefaultBootstrapContext(java.lang.Class,org.springframework.test.context.CacheAwareContextLoaderDelegate)]
    12:46:45.127 [Test worker] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating TestContextBootstrapper for test class [org.example.TestOne] from class [org.springframework.boot.test.context.SpringBootTestContextBootstrapper]
    12:46:45.139 [Test worker] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Neither @ContextConfiguration nor @ContextHierarchy found for test class [org.example.TestOne], using SpringBootContextLoader
    12:46:45.141 [Test worker] DEBUG org.springframework.test.context.support.AbstractContextLoader - Did not detect default resource location for test class [org.example.TestOne]: class path resource [org/example/TestOne-context.xml] does not exist
    12:46:45.142 [Test worker] DEBUG org.springframework.test.context.support.AbstractContextLoader - Did not detect default resource location for test class [org.example.TestOne]: class path resource [org/example/TestOneContext.groovy] does not exist
    12:46:45.142 [Test worker] INFO org.springframework.test.context.support.AbstractContextLoader - Could not detect default resource locations for test class [org.example.TestOne]: no resource found for suffixes {-context.xml, Context.groovy}.
    12:46:45.143 [Test worker] INFO org.springframework.test.context.support.AnnotationConfigContextLoaderUtils - Could not detect default configuration classes for test class [org.example.TestOne]: TestOne does not declare any static, non-private, non-final, nested classes annotated with @Configuration.
    12:46:45.186 [Test worker] DEBUG org.springframework.test.context.support.ActiveProfilesUtils - Could not find an 'annotation declaring class' for annotation type [org.springframework.test.context.ActiveProfiles] and class [org.example.TestOne]
    12:46:45.232 [Test worker] DEBUG org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider - Identified candidate component class: file [/home/pzapasnik/IdeaProjects/springmockk-bug/build/classes/kotlin/main/org/example/App.class]
    12:46:45.233 [Test worker] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Found @SpringBootConfiguration org.example.App for test class org.example.TestOne
    12:46:45.291 [Test worker] DEBUG org.springframework.boot.test.context.SpringBootTestContextBootstrapper - @TestExecutionListeners is not present for class [org.example.TestOne]: using defaults.
    12:46:45.292 [Test worker] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Loaded default TestExecutionListener class names from location [META-INF/spring.factories]: [com.ninjasquad.springmockk.MockkTestExecutionListener, com.ninjasquad.springmockk.ClearMocksTestExecutionListener, org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener, org.springframework.boot.test.autoconfigure.webservices.client.MockWebServiceServerTestExecutionListener, org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener, org.springframework.test.context.web.ServletTestExecutionListener, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener, org.springframework.test.context.support.DependencyInjectionTestExecutionListener, org.springframework.test.context.support.DirtiesContextTestExecutionListener, org.springframework.test.context.transaction.TransactionalTestExecutionListener, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener, org.springframework.test.context.event.EventPublishingTestExecutionListener]
    12:46:45.446 [Test worker] DEBUG org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Skipping candidate TestExecutionListener [org.springframework.test.context.transaction.TransactionalTestExecutionListener] due to a missing dependency. Specify custom listener classes or make the default listener classes and their required dependencies available. Offending class: [org/springframework/transaction/interceptor/TransactionAttributeSource]
    12:46:45.447 [Test worker] DEBUG org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Skipping candidate TestExecutionListener [org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener] due to a missing dependency. Specify custom listener classes or make the default listener classes and their required dependencies available. Offending class: [org/springframework/transaction/interceptor/TransactionAttribute]
    12:46:45.447 [Test worker] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Using TestExecutionListeners: [org.springframework.test.context.web.ServletTestExecutionListener@3cc0a6b3, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener@413e5ccd, com.ninjasquad.springmockk.MockkTestExecutionListener@634e33a5, org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener@60c8ab4c, org.springframework.boot.test.autoconfigure.SpringBootDependencyInjectionTestExecutionListener@59046cd8, org.springframework.test.context.support.DirtiesContextTestExecutionListener@6a6f8b01, org.springframework.test.context.event.EventPublishingTestExecutionListener@782e5ef2, com.ninjasquad.springmockk.ClearMocksTestExecutionListener@5d990870, org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener@2781cdb7, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener@31207dc5, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener@3bf37cdd, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener@2ebc395b, org.springframework.boot.test.autoconfigure.webservices.client.MockWebServiceServerTestExecutionListener@779a54e, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener@35053e31]
    12:46:45.450 [Test worker] DEBUG org.springframework.test.context.support.AbstractDirtiesContextTestExecutionListener - Before test class: context [DefaultTestContext@471fee0d testClass = TestOne, testInstance = [null], testMethod = [null], testException = [null], mergedContextConfiguration = [WebMergedContextConfiguration@2f731ce4 testClass = TestOne, locations = '{}', classes = '{class org.example.App}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true, server.port=0}', contextCustomizers = set[MockkContextCustomizer(definitions=[[SpykDefinition@592c4ac7 name = [null], typeToSpy = org.example.service.SomeService, clear = AFTER]]), org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@0, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizerFactory$Customizer@2f30d72, org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@79b96676, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@2ae8fcc7, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.web.client.TestRestTemplateContextCustomizer@7996153a, org.springframework.boot.test.context.SpringBootTestArgs@1], resourceBasePath = 'src/main/webapp', contextLoader = 'org.springframework.boot.test.context.SpringBootContextLoader', parent = [null]], attributes = map['org.springframework.test.context.web.ServletTestExecutionListener.activateListener' -> false]], class annotated with @DirtiesContext [false] with mode [null].
    12:46:45.527 [Test worker] DEBUG org.springframework.test.context.support.TestPropertySourceUtils - Adding inlined properties to environment: {spring.jmx.enabled=false, org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true, server.port=0}

      .   ____          _            __ _ _
     /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
    ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
     \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
      '  |____| .__|_| |_|_| |_\__, | / / / /
     =========|_|==============|___/=/_/_/_/
     :: Spring Boot ::        (v2.3.2.RELEASE)

    2020-08-06 12:46:46.068  INFO 17100 --- [    Test worker] org.example.TestOne                      : Starting TestOne on zapas-work with PID 17100 (started by pzapasnik in /home/pzapasnik/IdeaProjects/springmockk-bug)
    2020-08-06 12:46:46.069  INFO 17100 --- [    Test worker] org.example.TestOne                      : No active profile set, falling back to default profiles: default
    2020-08-06 12:46:46.625  INFO 17100 --- [    Test worker] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 0 (http)
    2020-08-06 12:46:46.634  INFO 17100 --- [    Test worker] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
    2020-08-06 12:46:46.634  INFO 17100 --- [    Test worker] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.37]
    2020-08-06 12:46:46.696  INFO 17100 --- [    Test worker] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
    2020-08-06 12:46:46.696  INFO 17100 --- [    Test worker] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 616 ms
OpenJDK 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended
    2020-08-06 12:46:47.710  INFO 17100 --- [    Test worker] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
    2020-08-06 12:46:48.022  INFO 17100 --- [    Test worker] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 35135 (http) with context path ''
    2020-08-06 12:46:48.033  INFO 17100 --- [    Test worker] org.example.TestOne                      : Started TestOne in 2.503 seconds (JVM running for 3.425)

TestTwo STANDARD_OUT
    2020-08-06 12:46:48.319  INFO 17100 --- [    Test worker] .b.t.c.SpringBootTestContextBootstrapper : Neither @ContextConfiguration nor @ContextHierarchy found for test class [org.example.TestTwo], using SpringBootContextLoader
    2020-08-06 12:46:48.333  INFO 17100 --- [    Test worker] o.s.t.c.support.AbstractContextLoader    : Could not detect default resource locations for test class [org.example.TestTwo]: no resource found for suffixes {-context.xml, Context.groovy}.
    2020-08-06 12:46:48.333  INFO 17100 --- [    Test worker] t.c.s.AnnotationConfigContextLoaderUtils : Could not detect default configuration classes for test class [org.example.TestTwo]: TestTwo does not declare any static, non-private, non-final, nested classes annotated with @Configuration.
    2020-08-06 12:46:48.336  INFO 17100 --- [    Test worker] .b.t.c.SpringBootTestContextBootstrapper : Found @SpringBootConfiguration org.example.App for test class org.example.TestTwo
    2020-08-06 12:46:48.338  INFO 17100 --- [    Test worker] .b.t.c.SpringBootTestContextBootstrapper : Loaded default TestExecutionListener class names from location [META-INF/spring.factories]: [com.ninjasquad.springmockk.MockkTestExecutionListener, com.ninjasquad.springmockk.ClearMocksTestExecutionListener, org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener, org.springframework.boot.test.autoconfigure.webservices.client.MockWebServiceServerTestExecutionListener, org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener, org.springframework.test.context.web.ServletTestExecutionListener, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener, org.springframework.test.context.support.DependencyInjectionTestExecutionListener, org.springframework.test.context.support.DirtiesContextTestExecutionListener, org.springframework.test.context.transaction.TransactionalTestExecutionListener, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener, org.springframework.test.context.event.EventPublishingTestExecutionListener]
    2020-08-06 12:46:48.342  INFO 17100 --- [    Test worker] .b.t.c.SpringBootTestContextBootstrapper : Using TestExecutionListeners: [org.springframework.test.context.web.ServletTestExecutionListener@4a085342, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener@489913d3, com.ninjasquad.springmockk.MockkTestExecutionListener@21bb4b15, org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener@309d7632, org.springframework.boot.test.autoconfigure.SpringBootDependencyInjectionTestExecutionListener@3807b120, org.springframework.test.context.support.DirtiesContextTestExecutionListener@38802a78, org.springframework.test.context.event.EventPublishingTestExecutionListener@43182d9e, com.ninjasquad.springmockk.ClearMocksTestExecutionListener@186fef29, org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener@1d64d3b5, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener@248ef98b, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener@26784459, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener@4109f118, org.springframework.boot.test.autoconfigure.webservices.client.MockWebServiceServerTestExecutionListener@7a4b7bf7, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener@29da8794]

      .   ____          _            __ _ _
     /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
    ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
     \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
      '  |____| .__|_| |_|_| |_\__, | / / / /
     =========|_|==============|___/=/_/_/_/
     :: Spring Boot ::        (v2.3.2.RELEASE)

    2020-08-06 12:46:48.390  INFO 17100 --- [    Test worker] org.example.TestTwo                      : Starting TestTwo on zapas-work with PID 17100 (started by pzapasnik in /home/pzapasnik/IdeaProjects/springmockk-bug)
    2020-08-06 12:46:48.390  INFO 17100 --- [    Test worker] org.example.TestTwo                      : No active profile set, falling back to default profiles: default
    2020-08-06 12:46:48.603  INFO 17100 --- [    Test worker] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 0 (http)
    2020-08-06 12:46:48.604  INFO 17100 --- [    Test worker] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
    2020-08-06 12:46:48.604  INFO 17100 --- [    Test worker] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.37]
    2020-08-06 12:46:48.616  INFO 17100 --- [    Test worker] o.a.c.c.C.[Tomcat-1].[localhost].[/]     : Initializing Spring embedded WebApplicationContext
    2020-08-06 12:46:48.617  INFO 17100 --- [    Test worker] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 224 ms
    2020-08-06 12:46:48.718  INFO 17100 --- [    Test worker] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
    2020-08-06 12:46:48.811  INFO 17100 --- [    Test worker] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 43657 (http) with context path ''
    2020-08-06 12:46:48.814  INFO 17100 --- [    Test worker] org.example.TestTwo                      : Started TestTwo in 0.452 seconds (JVM running for 4.206)
2020-08-06 12:46:48.854  INFO 17100 --- [extShutdownHook] o.s.s.concurrent.ThreadPoolTaskExecutor  : Shutting down ExecutorService 'applicationTaskExecutor'
2020-08-06 12:46:48.854  INFO 17100 --- [extShutdownHook] o.s.s.concurrent.ThreadPoolTaskExecutor  : Shutting down ExecutorService 'applicationTaskExecutor'

BUILD SUCCESSFUL in 5s
3 actionable tasks: 2 executed, 1 up-to-date

After downgrading to 2.0.1, the output is a bit different:

$ ./gradlew test

> Task :test

TestOne STANDARD_OUT
    12:50:37.591 [Test worker] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating CacheAwareContextLoaderDelegate from class [org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate]
    12:50:37.598 [Test worker] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating BootstrapContext using constructor [public org.springframework.test.context.support.DefaultBootstrapContext(java.lang.Class,org.springframework.test.context.CacheAwareContextLoaderDelegate)]
    12:50:37.615 [Test worker] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating TestContextBootstrapper for test class [org.example.TestOne] from class [org.springframework.boot.test.context.SpringBootTestContextBootstrapper]
    12:50:37.625 [Test worker] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Neither @ContextConfiguration nor @ContextHierarchy found for test class [org.example.TestOne], using SpringBootContextLoader
    12:50:37.627 [Test worker] DEBUG org.springframework.test.context.support.AbstractContextLoader - Did not detect default resource location for test class [org.example.TestOne]: class path resource [org/example/TestOne-context.xml] does not exist
    12:50:37.627 [Test worker] DEBUG org.springframework.test.context.support.AbstractContextLoader - Did not detect default resource location for test class [org.example.TestOne]: class path resource [org/example/TestOneContext.groovy] does not exist
    12:50:37.628 [Test worker] INFO org.springframework.test.context.support.AbstractContextLoader - Could not detect default resource locations for test class [org.example.TestOne]: no resource found for suffixes {-context.xml, Context.groovy}.
    12:50:37.628 [Test worker] INFO org.springframework.test.context.support.AnnotationConfigContextLoaderUtils - Could not detect default configuration classes for test class [org.example.TestOne]: TestOne does not declare any static, non-private, non-final, nested classes annotated with @Configuration.
    12:50:37.666 [Test worker] DEBUG org.springframework.test.context.support.ActiveProfilesUtils - Could not find an 'annotation declaring class' for annotation type [org.springframework.test.context.ActiveProfiles] and class [org.example.TestOne]
    12:50:37.699 [Test worker] DEBUG org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider - Identified candidate component class: file [/home/pzapasnik/IdeaProjects/springmockk-bug/build/classes/kotlin/main/org/example/App.class]
    12:50:37.699 [Test worker] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Found @SpringBootConfiguration org.example.App for test class org.example.TestOne
    12:50:37.747 [Test worker] DEBUG org.springframework.boot.test.context.SpringBootTestContextBootstrapper - @TestExecutionListeners is not present for class [org.example.TestOne]: using defaults.
    12:50:37.747 [Test worker] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Loaded default TestExecutionListener class names from location [META-INF/spring.factories]: [com.ninjasquad.springmockk.MockkTestExecutionListener, com.ninjasquad.springmockk.ClearMocksTestExecutionListener, org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener, org.springframework.boot.test.autoconfigure.webservices.client.MockWebServiceServerTestExecutionListener, org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener, org.springframework.test.context.web.ServletTestExecutionListener, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener, org.springframework.test.context.support.DependencyInjectionTestExecutionListener, org.springframework.test.context.support.DirtiesContextTestExecutionListener, org.springframework.test.context.transaction.TransactionalTestExecutionListener, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener, org.springframework.test.context.event.EventPublishingTestExecutionListener]
    12:50:37.883 [Test worker] DEBUG org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Skipping candidate TestExecutionListener [org.springframework.test.context.transaction.TransactionalTestExecutionListener] due to a missing dependency. Specify custom listener classes or make the default listener classes and their required dependencies available. Offending class: [org/springframework/transaction/interceptor/TransactionAttributeSource]
    12:50:37.883 [Test worker] DEBUG org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Skipping candidate TestExecutionListener [org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener] due to a missing dependency. Specify custom listener classes or make the default listener classes and their required dependencies available. Offending class: [org/springframework/transaction/interceptor/TransactionAttribute]
    12:50:37.883 [Test worker] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Using TestExecutionListeners: [org.springframework.test.context.web.ServletTestExecutionListener@66cc9808, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener@132a013b, com.ninjasquad.springmockk.MockkTestExecutionListener@18f8ce1f, org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener@56e04925, org.springframework.boot.test.autoconfigure.SpringBootDependencyInjectionTestExecutionListener@54ee9729, org.springframework.test.context.support.DirtiesContextTestExecutionListener@178e6756, org.springframework.test.context.event.EventPublishingTestExecutionListener@49d8db8e, com.ninjasquad.springmockk.ClearMocksTestExecutionListener@1d250af1, org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener@3d5291a3, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener@5982e588, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener@5689519d, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener@634ebb3f, org.springframework.boot.test.autoconfigure.webservices.client.MockWebServiceServerTestExecutionListener@4ab8e17c, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener@4d8e306]
    12:50:37.885 [Test worker] DEBUG org.springframework.test.context.support.AbstractDirtiesContextTestExecutionListener - Before test class: context [DefaultTestContext@67a6cf79 testClass = TestOne, testInstance = [null], testMethod = [null], testException = [null], mergedContextConfiguration = [WebMergedContextConfiguration@79b58c1c testClass = TestOne, locations = '{}', classes = '{class org.example.App}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true, server.port=0}', contextCustomizers = set[MockkContextCustomizer(definitions=[[SpykDefinition@bf52167 name = [null], typeToSpy = org.example.service.SomeService, clear = AFTER]]), org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@0, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizerFactory$Customizer@20e5ecc0, org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@7aee03b1, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@7cac51a8, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.web.client.TestRestTemplateContextCustomizer@44d49cbe, org.springframework.boot.test.context.SpringBootTestArgs@1], resourceBasePath = 'src/main/webapp', contextLoader = 'org.springframework.boot.test.context.SpringBootContextLoader', parent = [null]], attributes = map['org.springframework.test.context.web.ServletTestExecutionListener.activateListener' -> false]], class annotated with @DirtiesContext [false] with mode [null].
    12:50:37.945 [Test worker] DEBUG org.springframework.test.context.support.TestPropertySourceUtils - Adding inlined properties to environment: {spring.jmx.enabled=false, org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true, server.port=0}

      .   ____          _            __ _ _
     /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
    ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
     \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
      '  |____| .__|_| |_|_| |_\__, | / / / /
     =========|_|==============|___/=/_/_/_/
     :: Spring Boot ::        (v2.3.2.RELEASE)

    2020-08-06 12:50:38.436  INFO 17546 --- [    Test worker] org.example.TestOne                      : Starting TestOne on zapas-work with PID 17546 (started by pzapasnik in /home/pzapasnik/IdeaProjects/springmockk-bug)
    2020-08-06 12:50:38.437  INFO 17546 --- [    Test worker] org.example.TestOne                      : No active profile set, falling back to default profiles: default
    2020-08-06 12:50:38.953  INFO 17546 --- [    Test worker] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 0 (http)
    2020-08-06 12:50:38.960  INFO 17546 --- [    Test worker] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
    2020-08-06 12:50:38.960  INFO 17546 --- [    Test worker] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.37]
    2020-08-06 12:50:39.011  INFO 17546 --- [    Test worker] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
    2020-08-06 12:50:39.011  INFO 17546 --- [    Test worker] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 563 ms
OpenJDK 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended
    2020-08-06 12:50:39.986  INFO 17546 --- [    Test worker] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
    2020-08-06 12:50:40.279  INFO 17546 --- [    Test worker] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 38747 (http) with context path ''
    2020-08-06 12:50:40.292  INFO 17546 --- [    Test worker] org.example.TestOne                      : Started TestOne in 2.344 seconds (JVM running for 3.211)

TestTwo STANDARD_OUT
    2020-08-06 12:50:40.554  INFO 17546 --- [    Test worker] .b.t.c.SpringBootTestContextBootstrapper : Neither @ContextConfiguration nor @ContextHierarchy found for test class [org.example.TestTwo], using SpringBootContextLoader
    2020-08-06 12:50:40.555  INFO 17546 --- [    Test worker] o.s.t.c.support.AbstractContextLoader    : Could not detect default resource locations for test class [org.example.TestTwo]: no resource found for suffixes {-context.xml, Context.groovy}.
    2020-08-06 12:50:40.555  INFO 17546 --- [    Test worker] t.c.s.AnnotationConfigContextLoaderUtils : Could not detect default configuration classes for test class [org.example.TestTwo]: TestTwo does not declare any static, non-private, non-final, nested classes annotated with @Configuration.
    2020-08-06 12:50:40.557  INFO 17546 --- [    Test worker] .b.t.c.SpringBootTestContextBootstrapper : Found @SpringBootConfiguration org.example.App for test class org.example.TestTwo
    2020-08-06 12:50:40.558  INFO 17546 --- [    Test worker] .b.t.c.SpringBootTestContextBootstrapper : Loaded default TestExecutionListener class names from location [META-INF/spring.factories]: [com.ninjasquad.springmockk.MockkTestExecutionListener, com.ninjasquad.springmockk.ClearMocksTestExecutionListener, org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener, org.springframework.boot.test.autoconfigure.webservices.client.MockWebServiceServerTestExecutionListener, org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener, org.springframework.test.context.web.ServletTestExecutionListener, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener, org.springframework.test.context.support.DependencyInjectionTestExecutionListener, org.springframework.test.context.support.DirtiesContextTestExecutionListener, org.springframework.test.context.transaction.TransactionalTestExecutionListener, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener, org.springframework.test.context.event.EventPublishingTestExecutionListener]
    2020-08-06 12:50:40.561  INFO 17546 --- [    Test worker] .b.t.c.SpringBootTestContextBootstrapper : Using TestExecutionListeners: [org.springframework.test.context.web.ServletTestExecutionListener@7b3a5311, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener@4523ce29, com.ninjasquad.springmockk.MockkTestExecutionListener@7c976ba7, org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener@3c4eb0ef, org.springframework.boot.test.autoconfigure.SpringBootDependencyInjectionTestExecutionListener@15c5deac, org.springframework.test.context.support.DirtiesContextTestExecutionListener@4e4c18bb, org.springframework.test.context.event.EventPublishingTestExecutionListener@9c18886, com.ninjasquad.springmockk.ClearMocksTestExecutionListener@40c18899, org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener@7b4a1e93, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener@55ed5881, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener@506d6f02, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener@1c24a0d6, org.springframework.boot.test.autoconfigure.webservices.client.MockWebServiceServerTestExecutionListener@37b18b47, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener@8a7e460]
2020-08-06 12:50:40.597  INFO 17546 --- [extShutdownHook] o.s.s.concurrent.ThreadPoolTaskExecutor  : Shutting down ExecutorService 'applicationTaskExecutor'

BUILD SUCCESSFUL in 4s
3 actionable tasks: 2 executed, 1 up-to-date

As you can see, in 2.0.1 there is only one Spring Boot banner (the context is not reloaded between TestOne and TestTwo), which is the desired behaviour.

Most probably the same bug as spring-projects/spring-boot#22566. When I have some time, I will try to port the fix (even though the fix is not available in any released Spring Boot version yet).

Thanks for the issue and for the repro project @pzapasni.

I've confirmed that it was indeed a Spring Boot bug, and that reporting the fix from Spring Boot (which has not been released yet) to SpringMockK fixes the issue.

I've released version 2.0.3. It should be available in Maven Central soon.

Great, thanks for the swift response @jnizet!