1. Learn
  2. /
  3. Courses
  4. /
  5. Introduction to Testing in Java

Connected

Exercise

Username validation

You are writing the signup form for your website and you are currently working on the username validation. It's a boolean true/false method, however it has many branches and you want to make sure they can all be reached and will behave as expected.

To fully verify this method, you need to write multiple tests, one for each type of scenario. Fortunately, this is not too complicated.

The necessary JUnit packages have been imported for you.

Instructions

100 XP
  • Enter a username that is too short (less than 3 characters) and will fail the validation in the test that verifies the username length check.
  • Pass the username to the .isValidUsername() method and store the result.
  • Assert that the null case fails username validation.