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
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() {
}
}
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);
}
}
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>