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 an exception test

  1. Create a new Java project with the following structure in Eclipse:
    Time for action – writing an exception test
  2. Create a new class with name ExceptionTest and add the following code to it:
    package test.exception;
    
    import java.io.IOException;
    
    import org.testng.annotations.Test;
    
    public class ExceptionTest {
      @Test(expectedExceptions={IOException.class})
      public void exceptionTestOne() throws Exception{
        throw new IOException();
      }
    
      @Test(expectedExceptions={IOException.class,NullPointerException.class})
      public void exceptionTestTwo() throws Exception{
        throw new Exception();
      }
    
    }

    The preceding class contains two test methods, each throwing one particular kind ...

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