0

How to check does a method throw an exception or not in Junit in @Test field ??

for example:

@Test
public void testGenerateInvalidStudentData() {
    //TODO: check does studentIdGenerator.generate(null,2); 
    //      throw IllegalArgumentException or no.
}
Federico klez Culloca
  • 26,308
  • 17
  • 56
  • 95

1 Answers1

0

Use @Test(expected = IllegalArgumentException.class)

SoT
  • 898
  • 1
  • 15
  • 36