Can a JUnit test method throws exception?
In order to test the exception thrown by any method in JUnit 4, you need to use @Test(expected=IllegalArgumentException.class) annotation. You can replace IllegalArgumentException.class with any other exception
Read more: How to test Exception thrown by a Java Method in JUnit? Example
assertThrows method in JUnit is for handling expected exception on that particular Method . Here is the Syntax Exception exception = assertThrows(NumberFormatException.class, () → { Integer.parseInt(“1a”); });