Spring-boot default profile for integration tests

后端 未结 11 1054
说谎
说谎 2020-12-07 14:49

Spring-boot utilizes Spring profiles (http://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-profiles.html) which allow for instance to have separate co

11条回答
  •  北海茫月
    2020-12-07 15:13

    As far as I know there is nothing directly addressing your request - but I can suggest a proposal that could help:

    You could use your own test annotation that is a meta annotation comprising @SpringBootTest and @ActiveProfiles("test"). So you still need the dedicated profile but avoid scattering the profile definition across all your test.

    This annotation will default to the profile test and you can override the profile using the meta annotation.

    @Retention(RetentionPolicy.RUNTIME)
    @Target(ElementType.TYPE)
    @SpringBootTest
    @ActiveProfiles
    public @interface MyApplicationTest {
      @AliasFor(annotation = ActiveProfiles.class, attribute = "profiles") String[] activeProfiles() default {"test"};
    }
    

提交回复
热议问题