What is the function of the @Parameters annotation in TestNG?

What is the function of the @Parameters annotation in TestNG?

A) To pass parameters to test methods from the testng.xml file
B) To group test methods
C) To specify the order of test execution
D) To handle exceptions during test execution

Answer:

A) To pass parameters to test methods from the testng.xml file

Explanation:

The @Parameters annotation in TestNG is used to pass parameters to test methods from the testng.xml file. This allows you to provide external data to your tests without hardcoding the values in the test methods.

For example:


@Test
@Parameters({"param1", "param2"})
public void testMethod(String param1, String param2) {
    // Test code using the parameters
}

In this example, param1 and param2 values will be passed to the testMethod() from the testng.xml file.

Reference links:

https://www.javaguides.net/p/top-java-libraries.html

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top