Skip to content
SDETRole
SDETRole

Username rules with text input

beginner Equivalence partitioning Challenge 3 of 10

A sign-up page checks usernames before creating an account. Write tests that expose every bug in ten buggy implementations.

The checker is a single regular expression, which is how most real validators are written, and each buggy copy changes it in one realistic way: a quantifier that is off by one, a character class that is too wide or too narrow, a missing anchor. Unlike a number, a username has two things to test at once. Its length behaves like a range, so it has boundaries. Its characters behave like sets, so each kind of character needs its own example. A test such as alice is valid in every way and finds nothing, so think about what a developer could have changed in the pattern and choose names that would behave differently.

Requirements

  • The username has 3 to 15 characters.
  • Allowed characters are letters (upper or lower case), digits and underscores.
  • The first character must be a letter or an underscore, not a digit.
  • The result is valid or invalid. Do not use a | character in a test value.

Expected output

Tests that match the specification and expose all 10 planted bugs.

Function under test

isValidUsername(username) → result

  • username text (any text without a | character)

How your tests are checked

  • ○Every expected value agrees with the specification
  • ○Your tests expose all 10 planted bugs

The correct implementation is the oracle. A bug counts as caught when one of your valid tests gives a different result on the buggy copy than on the correct code.

testsMutation-tested in your browser
#usernametextany text without a | characterexpected resultRemove
1
1 test

Ctrl/⌘ + Enter to check tests · your tests are saved in this browser

Results

Check your tests to see which planted bugs they catch.

Type to search across SDETRole.

Full-text search by Pagefind · runs in your browser Open search page →