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 – disabling a test method

  1. Create a new class inside the package test with name the DisableTestClass inside the same Java project created earlier.
  2. Add the following code to the newly created class:
    package test;
    
    import org.testng.annotations.Test;
    
    public class DisableTestClass {
    
      @Test(enabled=true)
      public void testMethodOne(){
        System.out.println("Test method one.");
      }
    
      @Test(enabled=false)
      public void testMethodTwo(){
        System.out.println("Test method two.");
      }
    
      @Test
      public void testMethodThree(){
        System.out.println("Test method three.");
      }
    
    }

    The preceding class contains three test methods out of which, two contain the attribute enabled with the values true and false respectively.

  3. Select and run the previous class as TestNG test in Eclipse. ...

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