JUnit 5 Meta Annotation

Explanation of JUnit 5 meta annotations

Meta Annotations

JUnit Jupiter supports a meta-annotation mechanism. This means you can define your own annotation by combining arbitrary annotations.

If the same annotation combination is used in several places, wrapping it into one custom annotation improves reuse.

It can also decouple tests from a specific implementation because tests can use a custom annotation instead of specifying an extension class directly with @ExtendWith.

A common pattern is to implement a ParameterResolver, then create a custom annotation that adds @ExtendWith(MyParameterResolver.class). Tests can then use that custom annotation and receive resolved method parameters.