O'Reilly logo

TestNg Beginner's Guide by Varun Menon

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action – writing a exception test verifying message

  1. Create a new class with the name ExceptionMessageTest inside the Java project created in the earlier section.
  2. Add the following code to it:
    package test.exception; import java.io.IOException; import org.testng.annotations.Test; public class ExceptionMessageTest { /** * Verifies the exception message based on the exact error message thrown. */ @Test(expectedExceptions={IOException.class},expectedExceptionsMessageRegExp="Pass Message test") public void exceptionMsgTestOne() throws Exception{ throw new IOException("Pass Message test"); } /** * Verifies the exception message using the regular exception. * This test verifies that the exception message contains a text "Message" in it. */ @Test(expectedExceptions={IOException.class},expectedExceptionsMessageRegExp=".* ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required