🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← 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?

  1. A.Wrap it in Thread.sleep
  2. B.Use @Test(expectedExceptions = SomeException.class)
  3. C.Mark the test enabled = false
  4. 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 →