Complete the code to declare a DataProvider method in TestNG.
import org.testng.annotations.DataProvider; @DataProvider(name = "testData") public Object[][] [1]() { return new Object[][] { {"user1", "pass1"}, {"user2", "pass2"} }; }
The method name for a DataProvider can be any valid method name. Here, getData is used as the method name.
Complete the test method annotation to use the DataProvider named "testData".
import org.testng.annotations.Test; @Test(dataProvider = [1]) public void loginTest(String username, String password) { // test code here }
The dataProvider attribute in the @Test annotation must match the name of the DataProvider method, which is "testData" here.
Fix the error in the DataProvider method signature to make it valid.
@DataProvider(name = "loginData") public [1] loginData() { return new Object[][] { {"admin", "1234"}, {"guest", "guest"} }; }
A DataProvider method must return an Object[][] array containing test data sets.
Fill both blanks to correctly link the DataProvider to the test method and accept parameters.
@Test(dataProvider = [1]) public void [2](String user, String pass) { System.out.println("User: " + user + ", Pass: " + pass); }
The test method must specify the correct DataProvider name and have a matching method name.
Fill all three blanks to create a DataProvider method and a test method that uses it with parameters.
import org.testng.annotations.DataProvider; import org.testng.annotations.Test; @DataProvider(name = [1]) public Object[][] [2]() { return new Object[][] { {"admin", "admin123"}, {"user", "user123"} }; } @Test(dataProvider = [3]) public void verifyLogin(String username, String password) { System.out.println(username + " logs in with " + password); }
The DataProvider name in the annotation and the dataProvider attribute in @Test must match exactly as strings. The method name must be a valid Java method name.