0
0
Selenium Javatesting~20 mins

Data providers for parameterization in Selenium Java - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Data Provider Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of a TestNG DataProvider with multiple parameters
Consider the following TestNG test method using a DataProvider. What will be the output when the test runs?
Selenium Java
import org.testng.annotations.*;

public class TestClass {
  @DataProvider(name = "dp")
  public Object[][] dataProvider() {
    return new Object[][] {
      {"user1", 1},
      {"user2", 2}
    };
  }

  @Test(dataProvider = "dp")
  public void testMethod(String username, int id) {
    System.out.println(username + "-" + id);
  }
}
Auser1-2\nuser2-1
BCompilation error due to wrong DataProvider signature
Cuser1\n1\nuser2\n2
Duser1-1\nuser2-2
Attempts:
2 left
💡 Hint
Look at how the DataProvider returns a 2D Object array and how parameters map to method arguments.
assertion
intermediate
2:00remaining
Correct assertion for parameterized test with DataProvider
You have a test method that receives two integers from a DataProvider and should assert their sum equals 10. Which assertion is correct?
Selenium Java
@Test(dataProvider = "numbers")
public void testSum(int a, int b) {
  // assertion here
}

@DataProvider(name = "numbers")
public Object[][] numbers() {
  return new Object[][] {
    {7, 3},
    {5, 5},
    {6, 4}
  };
}
AAssert.assertEquals(a + b, 10);
BAssert.assertTrue(a + b == 10);
CAssert.assertEquals(10, a + b);
DAssert.assertFalse(a + b != 10);
Attempts:
2 left
💡 Hint
Remember the order of actual and expected in Assert.assertEquals(actual, expected).
🔧 Debug
advanced
2:00remaining
Identify the error in DataProvider method
What error will occur when running this TestNG test with the given DataProvider?
Selenium Java
@DataProvider(name = "dp")
public Object dataProvider() {
  return new Object[] {"test1", "test2"};
}

@Test(dataProvider = "dp")
public void testMethod(String input) {
  System.out.println(input);
}
ATest runs successfully printing test1 and test2
Bjava.lang.IllegalArgumentException: DataProvider must return Object[][] or Iterator<Object[]>
CCompilation error due to missing @Test annotation
DNullPointerException at testMethod
Attempts:
2 left
💡 Hint
Check the return type of the DataProvider method and what TestNG expects.
framework
advanced
2:00remaining
Best practice for DataProvider with external data source
You want to read test data from a CSV file to use in a TestNG DataProvider. Which approach is best?
ARead the CSV file inside the DataProvider method and return Object[][] with parsed data
BHardcode CSV data inside the test method and ignore DataProvider
CManually copy CSV data into Java arrays and return from DataProvider
DUse @Parameters annotation instead of DataProvider for CSV data
Attempts:
2 left
💡 Hint
Think about maintainability and reusability of test data.
🧠 Conceptual
expert
2:00remaining
Why use DataProvider over @Parameters in TestNG?
Which statement best explains the advantage of using DataProvider for parameterization compared to @Parameters?
ADataProvider can only pass primitive types, @Parameters supports complex objects.
B@Parameters allows dynamic data generation at runtime, DataProvider requires static data only.
CDataProvider supports multiple sets of parameters for the same test method, enabling data-driven testing; @Parameters supports only single set from XML.
D@Parameters is faster and preferred for large data sets over DataProvider.
Attempts:
2 left
💡 Hint
Consider how many test runs each approach can generate from given data.