Bird
0
0

Which approach correctly handles this scenario to avoid test failures when a password is empty or null?

hard📝 framework Q15 of 15
Selenium Java - TestNG Integration
You want to test a login form with multiple username and password combinations using a DataProvider. Which approach correctly handles this scenario to avoid test failures when a password is empty or null?
@DataProvider(name = "loginData")
public Object[][] loginData() {
    return new Object[][] {
        {"user1", "pass1"},
        {"user2", ""},
        {"user3", null}
    };
}

@Test(dataProvider = "loginData")
public void testLogin(String username, String password) {
    // Test logic here
}
ARemove entries with empty or null passwords from DataProvider
BAdd validation inside testLogin to skip or handle empty/null passwords
CChange DataProvider to return only usernames without passwords
DUse separate test methods for each username-password pair
Step-by-Step Solution
Solution:
  1. Step 1: Recognize the need to handle edge cases in test method

    Empty or null passwords can cause test failures if not handled properly.
  2. Step 2: Implement validation inside testLogin method

    Adding checks to skip or handle empty/null passwords prevents failures and tests robustness.
  3. Final Answer:

    Add validation inside testLogin to skip or handle empty/null passwords -> Option B
  4. Quick Check:

    Handle edge cases inside test method [OK]
Quick Trick: Validate inputs inside test to handle empty or null values [OK]
Common Mistakes:
  • Removing test data instead of handling it
  • Ignoring null or empty values causing failures
  • Splitting tests unnecessarily instead of parameterizing

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes