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 – providing optional values

Perform the following steps to provide optional values:

  1. Create a new class file with the name OptionalTest inside the Java project created earlier.
  2. Copy the following code to the said Java file and save it.
    package test.parameter;
    
    import org.testng.annotations.Optional;
    import org.testng.annotations.Parameters;
    import org.testng.annotations.Test;
    
    public class OptionalTest {
      @Parameters({"optional-value"})
      @Test
      public void optionTest(@Optional("optional value")String value){
        System.out.println("This is: "+value);    
      }
    
    }

    The preceding class file contains a single test method that takes one parameter as input. The said test method on execution prints the parameter value that is passed onto the console using the ...

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