I write a spring-boot test and created a custom annotation:
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@SpringBootTest
@AutoConfigureMockMvc
@ActiveProfiles("integration-test")
public @interface IntegrationTest {
String[] properties() default {};
}
As you can see, I’ve defined the properties attribute to have the possibility to override properties like that:
@IntegrationTest(properties = {"my.property=value"})
public class MyIntegrationTest {
// test code here
}
I don’t have any additional configurations and value of my attribute is automatic put into @SpringBootTest(properties = ), that is what I actually wanted to achieve.
But now I’m wondering how it is understood that the value of this attribute should be put in @SpringBootTest(properties = )?
>Solution :
You should annotate the properties with @AliasFor as follows:
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@SpringBootTest
@AutoConfigureMockMvc
@ActiveProfiles("integration-test")
public @interface IntegrationTest {
@AliasFor(annotation = SpringBootTest.class, attribute = "properties")
String[] properties() default {};
}