Pushpraj Singh
Pushpraj Singh

Reputation: 61

Method Skipped,when run with testng TEST annotation.How to provide parameters? I went to testng documentation but couldn't understand, please guide

Code:

package tests;

import org.testng.annotations.Test;

@Test
public class SearchText {


    public void createzoo(String[] args) {  

        String[] elems = {"lion", "tiger", "duck"};  
        System.out.println(elems[0]);
        System.out.println(elems[1]);
        System.out.println(elems[2]);
    }
}

Results:

SKIPPED: createzoo org.testng.TestNGException: Method createzoo requires 1 parameters but 0 were supplied in the @Test annotation.

Upvotes: 2

Views: 9793

Answers (3)

bamjuggler
bamjuggler

Reputation: 41

The example createzoo method is not actually using the args passed in. Since it is not using them, just change the message signature to:

public void createzoo()

Most JUnit/TestNG tests do not take any arguments. You may be confusing it with the typical program that has a public static void main(String[] args)

Tests don't have a main() per se and the framework will run your tests for you.

Only use the parameters mentioned by others if you really need them and the method is going to do something with them.

Upvotes: 4

artdanil
artdanil

Reputation: 5082

You need to provide the value for the parameter String[] args in the createzoo method. Here are several ways to do it:

  • Use @Parameters annotation on the method and supply values in testng.xml file.
  • Dataprovider (also mentioned by Cedric in his response).
  • Put @Optional annotation on your parameter and supply default value.

Read TestNG documentation - it has a lot of examples on how to accomplish this.

Upvotes: 1

Cedric Beust
Cedric Beust

Reputation: 15608

Here is the relevant documentation: http://testng.org/doc/documentation-main.html#parameters-dataproviders

Upvotes: 0

Related Questions