I’ve been looking for resources on how to extend JUnit4 with my own annotations.
I’d like to be able to define a @ExpectedProblem with which I could label some of my tests. I’ve seen there seems to be some material on the net on how to extend TestNG, but I could fine none to extend JUnit4.
Has anyone here extended JUnit4 in the past?
Thanks
Depending on what you want your
@ExpectedProblemannotation to do, another option is to create a@Rule.This requires JUnit 4.7+, but should be simpler than implementing your own
Runner.For instance, if you want an annotation to say, “this test should throw an exception” then you’ll want to take a look at the
@ExpectedExceptionrule. Even if that’s not enough for your needs it can provide a good starting point for implementing your own rule.