java - Spontaneous up spring boot context in test -


i have issue spring-boot-test during deep dive in spring testcontext configuration.

example project: github example project

i have 3 spring configurations beans (config1 - heavyweight config, , need cache it)

i use @contexthierarchy separate configs in context, , expect config1 loaded once. (used @contexthierarchy because did not find analogue in spring-boot-test)

full code:

@contexthierarchy({     @contextconfiguration(classes = {config1.class}),     @contextconfiguration(classes = {config2.class}), }) 

if run test, config1 cached! however, see following:

started configtest1 

two times and

started configtest2 

only once. in opinion, possible because configtest1 cached testcontext (it happens, because configtest1 , configtest2 contained in same package)

that means spring boot spring context 3 times! why? see spring boot logo 3 times in log:

  .   ____          _            __ _ _  /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \  \\/  ___)| |_)| | | | | || (_| |  ) ) ) )   '  |____| .__|_| |_|_| |_\__, | / / / /  =========|_|==============|___/=/_/_/_/  :: spring boot ::        (v1.5.2.release) 

what mean behaviour? bug or feature? maybe wrong?

update1:

thanks lot. however, if set properties (or classes) in @springboottest in different order in 2 test classes – no configuration cached :(

@runwith(springrunner.class) @springboottest @contexthierarchy({     @contextconfiguration(classes = {config1.class}),     @contextconfiguration(classes = {config2.class}), }) public class configtest1 { 

and

@runwith(springrunner.class) @springboottest(properties = "property1=1") @contexthierarchy({     @contextconfiguration(classes = {config1.class}),     @contextconfiguration(classes = {config3.class}), }) public class configtest2 { 

in case there no properties – config1 cached! , in case – nothing cached

everything working should!

you're confused because of fact spring boot logs name of test class applicationcontext loaded. thus, see configtest1 twice in log, because 2 contexts loaded test class.

if add logging.level.org.springframework.test.context.cache=debug application.properties, you'll see following log output.

debug ... c.defaultcacheawarecontextloaderdelegate : storing applicationcontext in cache under key [[webmergedcontextconfiguration@7a765367 testclass = configtest1, locations = '{}', classes = '{class spring.test.mistake.delete.config1}', contextinitializerclasses = '[]', activeprofiles = '{}', propertysourcelocations = '{}', propertysourceproperties = '{org.springframework.boot.test.context.springboottestcontextbootstrapper=true}', contextcustomizers = set[org.springframework.boot.test.context.springboottestcontextcustomizer@643b1d11, org.springframework.boot.test.context.filter.excludefiltercontextcustomizer@6d00a15d, org.springframework.boot.test.mock.mockito.mockitocontextcustomizer@0, org.springframework.boot.test.autoconfigure.properties.propertymappingcontextcustomizer@0, org.springframework.boot.test.autoconfigure.web.servlet.webdrivercontextcustomizerfactory$customizer@475530b9], resourcebasepath = 'src/main/webapp', contextloader = 'org.springframework.boot.test.context.springbootcontextloader', parent = [null]]] debug ... c.defaultcacheawarecontextloaderdelegate : storing applicationcontext in cache under key [[webmergedcontextconfiguration@52feb982 testclass = configtest1, locations = '{}', classes = '{class spring.test.mistake.delete.config2}', contextinitializerclasses = '[]', activeprofiles = '{}', propertysourcelocations = '{}', propertysourceproperties = '{org.springframework.boot.test.context.springboottestcontextbootstrapper=true}', contextcustomizers = set[org.springframework.boot.test.context.springboottestcontextcustomizer@643b1d11, org.springframework.boot.test.context.filter.excludefiltercontextcustomizer@6d00a15d, org.springframework.boot.test.mock.mockito.mockitocontextcustomizer@0, org.springframework.boot.test.autoconfigure.properties.propertymappingcontextcustomizer@0, org.springframework.boot.test.autoconfigure.web.servlet.webdrivercontextcustomizerfactory$customizer@475530b9], resourcebasepath = 'src/main/webapp', contextloader = 'org.springframework.boot.test.context.springbootcontextloader', parent = [webmergedcontextconfiguration@7a765367 testclass = configtest1, locations = '{}', classes = '{class spring.test.mistake.delete.config1}', contextinitializerclasses = '[]', activeprofiles = '{}', propertysourcelocations = '{}', propertysourceproperties = '{org.springframework.boot.test.context.springboottestcontextbootstrapper=true}', contextcustomizers = set[org.springframework.boot.test.context.springboottestcontextcustomizer@643b1d11, org.springframework.boot.test.context.filter.excludefiltercontextcustomizer@6d00a15d, org.springframework.boot.test.mock.mockito.mockitocontextcustomizer@0, org.springframework.boot.test.autoconfigure.properties.propertymappingcontextcustomizer@0, org.springframework.boot.test.autoconfigure.web.servlet.webdrivercontextcustomizerfactory$customizer@475530b9], resourcebasepath = 'src/main/webapp', contextloader = 'org.springframework.boot.test.context.springbootcontextloader', parent = [null]]]] debug ... c.defaultcacheawarecontextloaderdelegate : storing applicationcontext in cache under key [[webmergedcontextconfiguration@5ddcc487 testclass = configtest2, locations = '{}', classes = '{class spring.test.mistake.delete.config3}', contextinitializerclasses = '[]', activeprofiles = '{}', propertysourcelocations = '{}', propertysourceproperties = '{org.springframework.boot.test.context.springboottestcontextbootstrapper=true}', contextcustomizers = set[org.springframework.boot.test.context.springboottestcontextcustomizer@643b1d11, org.springframework.boot.test.context.filter.excludefiltercontextcustomizer@6d00a15d, org.springframework.boot.test.mock.mockito.mockitocontextcustomizer@0, org.springframework.boot.test.autoconfigure.properties.propertymappingcontextcustomizer@0, org.springframework.boot.test.autoconfigure.web.servlet.webdrivercontextcustomizerfactory$customizer@475530b9], resourcebasepath = 'src/main/webapp', contextloader = 'org.springframework.boot.test.context.springbootcontextloader', parent = [webmergedcontextconfiguration@44c73c26 testclass = configtest2, locations = '{}', classes = '{class spring.test.mistake.delete.config1}', contextinitializerclasses = '[]', activeprofiles = '{}', propertysourcelocations = '{}', propertysourceproperties = '{org.springframework.boot.test.context.springboottestcontextbootstrapper=true}', contextcustomizers = set[org.springframework.boot.test.context.springboottestcontextcustomizer@643b1d11, org.springframework.boot.test.context.filter.excludefiltercontextcustomizer@6d00a15d, org.springframework.boot.test.mock.mockito.mockitocontextcustomizer@0, org.springframework.boot.test.autoconfigure.properties.propertymappingcontextcustomizer@0, org.springframework.boot.test.autoconfigure.web.servlet.webdrivercontextcustomizerfactory$customizer@475530b9], resourcebasepath = 'src/main/webapp', contextloader = 'org.springframework.boot.test.context.springbootcontextloader', parent = [null]]]] debug ... org.springframework.test.context.cache   : spring test applicationcontext cache statistics: [defaultcontextcache@478db956 size = 3, maxsize = 32, parentcontextcount = 1, hitcount = 11, misscount = 3] 

thus, there in fact 3 contexts loaded, namely 3 expect.


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -