Primarily:
@Test(expected=IllegalArgumentException.class)
should not be construed as an appropriate method, especially with such a general exception. The reason is that you have no control over which operator in your test method actually threw an exception. Also you cannot make any statements on the message label, reason, etc.
Using try-catch , exactly related to the line that is supposed to throw an exception, is the right way:
try { shouldThrow() fail("Expected exception"); } catch(XMLClientNotFound e) { assertThat(e).hasMessage("Expected message");
You can also try JUnit @Rule , which I wrote a while ago to make your test more readable.
source share