Sobes.tech
Middle

How would you test the phone field, starting from the frontend and ending with the backend?

sobes.tech AI

Answer from AI

Frontend Testing

  1. Input Validation:
    • Mask verification (if present).
    • Entering digits, letters, special characters to check blocking or handling of non-numeric values.
    • Entering phone numbers in various formats (international, domestic, short).
    • Entering too short/long numbers.
    • Error message verification for incorrect input.
  2. Boundaries:
    • Entering the minimum and maximum allowed number of digits.
    • Entering numbers at the boundary of allowed ranges (if specified).
  3. State:
    • Checking disabled/readonly states of the field.
    • Field state after unsuccessful/successful form submission.
    • Placeholder/hint text verification.
  4. UI/UX:
    • Proper display of the field on different resolutions and devices.
    • Keyboard navigation (Tab).
    • Accessibility features — e.g., presence of aria-tags.
  5. Automation:
    • Using frameworks (Selenium, Cypress, Playwright) for input and validation checks.
// Example of non-numeric character input check with Cypress
it('should not allow non-numeric input', () => {
  cy.get('input[name="phone"]').type('abcde').should('have.value', ''); // Check that the field is empty or contains only valid digits
});

Backend Testing

  1. Data Validation:
    • Data type checks (expecting string/number, but not other types).
    • Phone number format validation (using regex or specialized libraries).
    • Length check of the number.
    • Mandatory field presence check.
    • SQL injection or other vulnerability checks during data saving/processing.
    • Number uniqueness check if required (e.g., during user registration).
  2. Business Logic:
    • Proper handling of incoming number (normalization, formatting).
    • Integration with external services (e.g., for number verification).
    • Checking how the number is used in other parts of the system (notifications, reports).
  3. Performance:
    • Response time under high request load with phone numbers.
  4. Security:
    • Authorization and authentication checks when accessing data with phone numbers.
    • Data encryption at rest and in transit if confidential.
  5. API Testing:
    • Using tools (Postman, Rest Assured) to send requests with various phone number formats.
    • Response code checks (200, 400, 422, 500).
    • Response structure and content verification.
// Example of backend validation check with Rest Assured
@Test
public void testInvalidPhoneNumberFormat() {
    String requestBody = "{ \"phone\": \"invalid-number\" }";
    given().body(requestBody).post("/api/register")
           .then().statusCode(400) // Expect validation error
           .body("error", containsString("Invalid phone number format"));
}

Database Testing

  1. Data Type:
    • Check the field type in the database (e.g., VARCHAR with appropriate length).
  2. Data Integrity:
    • Constraint checks (NOT NULL, UNIQUE KEY).
  3. Storage:
    • Correct storage of the phone number after backend processing.
    • Number encryption if required.

Integration Testing

  1. Data transfer between frontend and backend with the phone number.
  2. Interaction of backend with database and external services when working with the phone number.

Negative Testing

  • Sending empty values.
  • Sending incorrect formats.
  • Sending values exceeding allowed length.
  • Simulating network or external service issues.

Sample Test Cases (General)

ID Description Testing Steps Expected Result Priority
TC-PH-001 Entering a valid Russian number 1. Open the form. 2. Enter "79123456789" in the phone field. 3. Submit the form. Form submitted successfully, number stored/processed correctly. High
TC-PH-002 Entering a number with an international prefix 1. Open the form. 2. Enter "+12125550101" in the phone field. 3. Submit the form. Form submitted successfully, number stored/processed with prefix consideration. Medium
TC-PH-003 Entering a number with letters 1. Open the form. 2. Enter "7912abc3456" in the phone field. Frontend blocks letter input or backend returns validation error. High
TC-PH-004 Entering a too short number 1. Open the form. 2. Enter "123" in the phone field. 3. Submit the form. Frontend or backend issues an error message "Number too short". High
TC-PH-005 Leaving the mandatory phone field empty 1. Open the form. 2. Leave the phone field empty. 3. Submit the form. Frontend or backend issues an error message "Phone field is required". High
TC-PH-006 Saving the number in the database Precondition: create a user with a valid number. Check the database record in the user table. Phone number stored correctly in the database with expected type and format. Medium