← Quiz: TestNG: all 10 questions
Quiz: TestNG · Question 8 of 10
How do you check that a method throws an exception in TestNG?
How do you check that a method throws an exception in TestNG?
- A.Wrap it in Thread.sleep
- B.Use @Test(expectedExceptions = SomeException.class)
- C.Mark the test enabled = false
- D.Use a listener
Answer & explanation
Correct answer: Use @Test(expectedExceptions = SomeException.class)
The test passes only if that exception is thrown.
Can you get the rest right without peeking?
Take the timed Quiz: TestNG quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →