How to Write Phone Number Validation Test Cases
In this how-to, we will walk through how to write sample test phone number validation test cases. Many applications collect your mobile number. Some examples of applications include purchasing on eCommerce websites, scheduling an appointment, or waiting for a call-back to your mobile number. As a result, creating sample test cases for phone number field applies to all testers. Follow along with this how-to and finish your application’s first test case by creating your account in our free test case management tool. Before starting our test case, we need to define the Acceptance Criteria.
What are the Acceptance Criteria for phone number field test cases?
As discussed in our requirements post, we must have functional requirements. So let’s go ahead and define them as such:
Description: “User must be able to enter their mobile phone number while registering their account.”
Abbreviated Acceptance Criteria:
- Validate the phone number can be entered depending on the country code.
- Validate error messages are thrown when invalid data is entered.
What are the Test Cases for Phone Number Validation?
- Validate the mobile number field enforces the correct number of characters for the region you are testing. For example a 10 digit mobile number:
- Must accept 10 digits ie. “5152133212”
- Must throw an error with less than 10 digits ie. “515213321”
- Must not accept more than 10 digits. ie. 51523235321
- Validate the formatting of the mobile number, based on business requirements. Examples of potential formats:
- Validate blank input space between the mobile number field is not accepted. Ex: 51532 12343
- Validate the mobile number input text box accepts copy and paste input.
- Based on requirements, verify the mobile number field is mandatory field or not.
Validate error messages are thrown if validation issues exist. Examples might include:
- Mobile number field entered with fewer characters than expected.
- Mobile number field entered with too many characters (if testing through the API, or the input field does not stop at a certain number).
- Not entering a mobile number field.
- Mobile number field has a special character.
- Validate a placeholder text exists for the mobile number input text box.
- Validate the correct mobile number data is persisted in the database when the Save or Next button is clicked.
- Validate the form can be saved by pressing the enter button with a valid mobile number.
- Depending on requirements, verify the country code and flag are displayed in the mobile number field.
Keep in mind there are diminishing returns to testing, and developers should be using a thoroughly tested library for some of this functionality. Here are some tests some folks might be tempted to run, but are not needed because they are using inbuilt operating system functionality not specific to the application.
- Validate the text box accepts 10 zero numbers in the mobile number field.
- Validate the mobile number field text box by entering 10 blank input spaces.
- Validate the mobile number text box does not accept alpha characters.
- Validate error is thrown when no value is entered in the mobile number field.
- Validate entering a special character in the mobile number field throws an error.
- Validate entering a 0 at the initial space of the mobile number field.
- Validate a specific error message is thrown when the user saves the form without a mobile number in the text box (assuming requirements state the field is mandatory).
The best thing you can do as a tester is discuss, with the developer, what the mobile number library code is doing and what it is not doing. Another quick sanity check is to review your developer’s code check-in for the story you are working on. Doing so can help target your testing efforts when testing the mobile number.
Writing Sample Test Cases
In this future section, we will go into detail on how to write valid mobile number test scenarios. If you already have your free AccelaTest test management account and want to be added to this complete test case, please email us at email@example.com.