2

I'm trying to do parameterization for TestNG in Eclipse but the annotation @parameter is not being shown. How to add @parameter annotation for TestNG in eclipse?

3 Answers 3

2

Are you trying to add TestNG parameters annotations to pass parameters to your test method? TestNG uses @Parameter annotation for this purpose. Try with capitalized letters.

import org.testng.annotations.Parameters;
@Parameters
public class helloWorldTest {
    @Parameters(value="blah")
    public void testHelloWord() {

    }

}
0

Here is how you pass parameters from your testng.xml file into your tests using TestNG. There are 2 ways you can do it:

import org.testng.annotations.Parameters;
import org.testng.ITestContext;

public class helloWorldTest {

    @Parameters(value="blah")
    @Test       
    public void testDirectParameters() {
        System.out.println(blah);
    }

    @Test       
    public void testIndirectParameters(ITestContext context) {
        String blahString = context.getCurrentXmlTest().getParameter("blah");
        System.out.println(blahString);
    }

}
0

including above make sure that you have included testng jar in your project. If you have maven:

<dependency>
    <groupId>org.testng</groupId>
    <artifactId>testng</artifactId>
    <version>6.9.4</version>
</dependency>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.