Spring profiles and testing

前端 未结 5 1875
耶瑟儿~
耶瑟儿~ 2020-12-24 10:36

I\'ve got a web application where I have the typical problem that it requires different configuration files for different environments. Some configuration is placed in the a

5条回答
  •  再見小時候
    2020-12-24 10:57

    @EnableConfigurationProperties needs to be there (you also can annotate your test class), the application-localtest.yml from test/resources will be loaded. A sample with jUnit5

    @ExtendWith(SpringExtension.class)
    @EnableConfigurationProperties
    @ContextConfiguration(classes = {YourClasses}, initializers = ConfigFileApplicationContextInitializer.class)
    @ActiveProfiles(profiles = "localtest")
    class TestActiveProfile {
    
        @Test
        void testActiveProfile(){
    
        }
    }
    

提交回复
热议问题