I would like to create an annotation as a syntax sugar for JUnit categories.
What I would like to achieve:
@Test
public void shouldDoSomeTesting() { ... }
@Wip
@Test
public void shouldBeATestWithWorkInProgress { ... }
I've tried something like this (Wip.class):
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
@Category(Wip.class)
public @interface Wip {}
But it didn't work. It works if I do this:
@Category(Wip.class)
@Test
public void shouldBeATestWithWorkInProgress { ... }
Is this possible? If yes, what am I doing wrong in the interface?
You can't create such meta annotation unless the framework evaluating them supports that.
JUnit4 doesn't. It only looks for annotations of exactly the types it knows.
There was discussion about adding that https://github.com/junit-team/junit4/issues/194
There is however support for meta-annotations in the upcoming JUnit 5. e.g. https://github.com/junit-team/junit5/issues/114
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With