I wanted to create a custom JUnit annotation, something similar to expected tag in @Test, but I want to also check the annotation message.
Any hints how to do that, or maybe there is something ready?
JUnit 4.9 tightened up the library's use of "rules" for tests, which I think might work as well as a custom annotation. Take a look at TestRule as a starting point. You can implement a rule based on that interface, and then use either the @ClassRule or (method-level) @Rule annotations to put them into play in your tests.
A good concrete example is ExpectedException, which lets you specify exceptions like the expected parameter for @Test does (and then some).
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