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 – passing parameters to test classes

Perform the following steps for passing parameters to test classes:

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

    The constructor of the previous test class takes one argument as an integer, which is assigned to a local variable param. This variable ...

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