Load different application.yml in SpringBoot Test

前端 未结 11 1137
天涯浪人
天涯浪人 2020-11-30 22:09

I\'m using a spring boot app which runs my src/main/resources/config/application.yml.

When I run my test case by :

@RunWith(SpringJUnit4ClassRunner.c         


        
11条回答
  •  爱一瞬间的悲伤
    2020-11-30 23:03

    A simple working configuration using

    @TestPropertySource and properties

    @SpringBootTest
    @RunWith(SpringJUnit4ClassRunner.class)
    @TestPropertySource(properties = {"spring.config.location=classpath:another.yml"})
    public class TestClass {
    
    
        @Test
    
        public void someTest() {
        }
    }
    

提交回复
热议问题