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 – dependency with the @Factory annotation

  1. Create a new class by the name DependencyTest under the test.classes package and replace the following code in it:
    package test.classes;
    import org.testng.annotations.Test;
    public class DependencyTest {
      private int param;
      public DependencyTest(int param){
        this.param = param;
      }
      @Test(dependsOnMethods={"testMethodTwo"})
      public void testMethodOne(){
        System.out.println("Test method one with param values: "+ this.param);
      }
      
      @Test
      public void testMethodTwo(){
        System.out.println("Test method two with param values: "+ this.param);
      }
    }

    This class contains two test methods testMethodOne and testMethodTwo, where testMethodOne depends on testMethodTwo. The constructor of the class takes one argument as ...

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