DEV Community

Cover image for How to Test SMS Verification Without Putting Your Personal Number in Your Test Data
Quackr
Quackr

Posted on

How to Test SMS Verification Without Putting Your Personal Number in Your Test Data

We run Quackr, a virtual phone number platform that lets developers and individuals receive SMS verifications without exposing a real number. One question comes up from developers more than any other: how do you test a phone verification flow properly? This is the approach we recommend.

The Problem With Using Your Own Number

Most developers test sign-up flows with their own phone number. It works, but your number ends up in staging databases, logs, error trackers, screenshots and bug tickets. Once it is spread across a project, you cannot take it back.

A phone number is also tied to banking, two-factor logins and family contacts, so it is worth keeping out of test data.

Three Ways To Test

  1. A fake SMS client. Put your sending code behind a small interface and swap in a fake in tests that records messages. This covers your logic: wrong codes, expired codes, lockouts and resend rules, with no phone and no cost.

  2. A free public number. Some sites list free temporary numbers. They are shared, so anyone can read the same inbox, including your code, and many platforms block them. Fine for a throwaway check, a poor choice for anything you care about.

  3. A rented virtual number. For real delivery tests you need a real number that is not yours. A virtual phone number is not tied to a SIM card, and you read its messages in a browser or through an API. Rented numbers are dedicated to you for the rental period (from a week to a year on Quackr) instead of being shown to everyone, which makes them a better fit for end to end tests and shared team accounts.

Here is a minimal fake client for option 1:

export interface SmsClient {
  send(to: string, body: string): Promise<void>;
}

// Used in tests: records messages instead of sending them
export class FakeSmsClient implements SmsClient {
  sent: { to: string; body: string }[] = [];

  async send(to: string, body: string) {
    this.sent.push({ to, body });
  }

  lastCode() {
    const last = this.sent.at(-1);
    return last?.body.match(/\d{4,8}/)?.[0];
  }
}
Enter fullscreen mode Exit fullscreen mode

What To Test In The Flow

Most bugs are not in sending the text. They are around it. Check these:

  • The happy path, where the code arrives and signs the user in.
  • A wrong code, with a clear error and limited tries.
  • An expired code, and the user asking for a new one.
  • Resend, where a new code replaces the old one and resends are rate limited.
  • Number formats, including with and without a plus sign, spaces and dashes.
  • Delivery delay, by waiting before entering the code.
  • Duplicate numbers across accounts.
  • Lost access, when a user no longer has the number.

The OTP That Never Arrives

If you test against large platforms, you may hit a problem that has nothing to do with your code. Some platforms flag certain number types, and the verification code simply never sends, with no error message.

Before you spend hours debugging your own flow, try the same test with a different number type. It is one of the quickest ways to tell a blocked number from a real bug.

Automating Verification In Tests

If your tests need numbers and codes without a person in the loop, you need programmatic access. Our API lets you receive SMS messages in real time as JSON, so your tests can read the code without a person in the loop. Details are at quackr.io/api. For AI agents, Quackr also has an MCP server, described at quackr.io/mcp.

Keeping Test Data Clean

  • Keep test numbers in your team password manager with a note on what each one is for.
  • Use reserved fictional numbers in unit tests (in North America, 555-0100 to 555-0199 are set aside for fiction) and a real rented number only for end to end runs.
  • Never copy real customer numbers into staging.
  • Remove phone numbers from logs and screenshots before sharing them.
  • Do not use a temporary number for accounts you need long term. If you stop using it you can lose the codes you need to log back in. Happy to answer questions about testing SMS verification, how number types affect delivery, or how to wire verification into whatever you are building.

Built by the team at Quackr, virtual phone numbers for SMS verification.

Top comments (0)