How to assert my exception message with JUnit Test annotation?

Posted by Jennifer | Updated on

Want to assert my exception message with JUnit Test annotation? You could use the @Rule annotation with ExpectedException, like this:

Note that the example in the ExpectedException docs is (currently) wrong – there’s no public constructor, so you have to use ExpectedException.none().


If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.

Related Questions & Answers