Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create annotation for JUnit category

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?

like image 334
Lucas Beier Avatar asked Feb 06 '23 21:02

Lucas Beier


1 Answers

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

like image 134
zapl Avatar answered Feb 23 '23 17:02

zapl