For the integration tests of my Spring Boot app, I have declared custom meta-annotations (a bit like Spring Boot's test slice annotations). How can I declare different TestExecutionListeners in each meta-annotation, and have all of them merged when running a test class?
I can only find mergeMode = MERGE_WITH_DEFAULTS
which merges the declared TestExecutionListener with the default ones, but not different custom Listeners declared in different places.
A minimal example:
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@TestExecutionListeners(
listeners = DbTestListener.class,
mergeMode = MERGE_WITH_DEFAULTS)
public @interface DbIntegrationTest {
}
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@TestExecutionListeners(
listeners = MessagingTestListener.class,
mergeMode = MERGE_WITH_DEFAULTS)
public @interface MessagingIntegrationTest {
}
@RunWith(SpringRunner.class)
@DbIntegrationTest
@MessagingIntegrationTest
public class ExampleTest {
// test cases here
}
As a result, I'd like to have both custom TestListeners and the default ones executed for my ExampleTest
.
Clarification: the above example is minimal as to show what I want. Of course like that it doesn't make much sense. My own composed annotations have much more setup in them which I haven't shown, and I have multiple layers of meta-annotations.