Challenge - 5 Problems
Data Provider Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2: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); } }
Attempts:
2 left
💡 Hint
Look at how the DataProvider returns a 2D Object array and how parameters map to method arguments.
✗ Incorrect
The DataProvider returns two sets of parameters: {"user1", 1} and {"user2", 2}. The test method receives these as (username, id) pairs and prints them concatenated with a dash. So the output lines are 'user1-1' and 'user2-2'.
❓ assertion
intermediate2: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} }; }
Attempts:
2 left
💡 Hint
Remember the order of actual and expected in Assert.assertEquals(actual, expected).
✗ Incorrect
In TestNG, Assert.assertEquals expects the first argument as actual value and second as expected. So Assert.assertEquals(a + b, 10) is correct. Option A has reversed parameters which can cause confusing messages. Options B and D are logically correct but less clear.
🔧 Debug
advanced2: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); }
Attempts:
2 left
💡 Hint
Check the return type of the DataProvider method and what TestNG expects.
✗ Incorrect
TestNG requires DataProvider methods to return Object[][] or Iterator
❓ framework
advanced2: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?
Attempts:
2 left
💡 Hint
Think about maintainability and reusability of test data.
✗ Incorrect
Reading CSV inside DataProvider allows dynamic, maintainable data-driven tests. Hardcoding or manual copying is error-prone and not scalable. @Parameters is for simple fixed parameters, not data-driven tests.
🧠 Conceptual
expert2:00remaining
Why use DataProvider over @Parameters in TestNG?
Which statement best explains the advantage of using DataProvider for parameterization compared to @Parameters?
Attempts:
2 left
💡 Hint
Consider how many test runs each approach can generate from given data.
✗ Incorrect
DataProvider can supply multiple parameter sets, running the test multiple times with different data (data-driven). @Parameters reads fixed parameters from XML and runs test once per method.