Override default Spring-Boot application.properties settings in Junit Test with dynamic value

前端 未结 4 1711
挽巷
挽巷 2020-12-10 16:56

I want to override properties defined in application.properties in tests, but @TestPropertySource only allows to provide predefined values.

What I need is to start a

4条回答
  •  青春惊慌失措
    2020-12-10 17:21

    As of Spring Framework 5.2.5 and Spring Boot 2.2.6 you can use Dynamic Properties in tests:

    @DynamicPropertySource
    static void dynamicProperties(DynamicPropertyRegistry registry) {
        registry.add("property.name", "value");
    }
    

提交回复
热议问题