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?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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).