Bird
0
0

Which assertion is best to use in the test class?

hard📝 Application Q9 of 15
Selenium Java - Page Object Model
You have a test class that consumes a page object with a method getUserName() returning a String. You want to assert that the username is not empty after login. Which assertion is best to use in the test class?
AAssert.assertEquals(getUserName(), "");
BAssert.assertTrue(getUserName() == null);
CAssert.assertFalse(getUserName().isEmpty());
DAssert.assertNull(getUserName());
Step-by-Step Solution
Solution:
  1. Step 1: Understand requirement

    Username should not be empty string after login.
  2. Step 2: Choose assertion to check non-empty string

    AssertFalse on isEmpty() returns true if string is not empty.
  3. Final Answer:

    Assert.assertFalse(getUserName().isEmpty()); -> Option C
  4. Quick Check:

    Check non-empty string with assertFalse(isEmpty()) [OK]
Quick Trick: Use assertFalse(string.isEmpty()) to check non-empty [OK]
Common Mistakes:
  • Checking for null instead of empty string
  • Using assertEquals with empty string incorrectly
  • Using assertNull when string is expected

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes