Load different application.yml in SpringBoot Test

前端 未结 11 1134
天涯浪人
天涯浪人 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条回答
  •  Happy的楠姐
    2020-11-30 22:54

    You can use @TestPropertySource to load different properties/yaml file

    @TestPropertySource(locations="classpath:test.properties")
    @RunWith(SpringJUnit4ClassRunner.class)
    @SpringApplicationConfiguration(Application.class)
    public class MyIntTest{
    
    }
    

    OR if you want to override only specific properties/yaml you can use

    @TestPropertySource(
            properties = {
                    "spring.jpa.hibernate.ddl-auto=validate",
                    "liquibase.enabled=false"
            }
    )
    

提交回复
热议问题