How to assert exception message in JUnit? Wed Jul 26 2017 From here, here and here. 123456789@Rulepublic ExpectedException expectedEx = ExpectedException.none();@Testpublic void shouldThrowRuntimeExceptionWhenEmployeeIDisNull() throws Exception { expectedEx.expect(RuntimeException.class); expectedEx.expectMessage("Employee ID is null"); // do something that should throw the exception...}