SMS Testing: Test Text Messages and OTP Codes with Real Phone Numbers
Test SMS verification codes, alerts and replies end to end: simulated checks for every commit, then automated tests that receive real text messages on a private phone number.

An application that texts its users depends on a chain of systems you don't fully control. Your code asks an SMS provider to send a message, the provider hands it to a carrier, the carrier delivers it to a phone, and the person types the code back into your app. A bug or a configuration change at any step stops someone from signing in, and the logs on your side can still say the message was sent.
SMS testing checks that chain. Some checks are fast and free and belong on every commit; others need a real phone number and belong before each release. This page covers both, and how to automate the second kind without a drawer of test phones.
What to test in an SMS flow
Start from what the person receiving the text needs, then work back to the parts you can check:
- The content. The message names your product, contains exactly one code or link, and fits in a single segment where that matters.
- Delivery and timing. The text reaches a real number in each country and number type you support, and arrives well before the code expires.
- The result. Entering the code signs the right person in, verifies the right phone or completes the right action.
- The failures. A wrong code is rejected, an expired code is rejected, a resend makes the earlier code stop working, and too many attempts lock the attempt.
- The route. The sender ID, the from-number and the provider's registration (for example US A2P 10DLC or toll-free verification) are the ones you expect, because carriers filter unregistered traffic.
Your SMS provider's dashboard answers part of the second question. The rest needs tests that read the text the way a user would.
Test your code without sending a real SMS
For checks that run on every change, replace the real SMS client with a fake sender that keeps messages in memory. Your test reads the code from that outbox, enters it and checks the result. Provider test modes work the same way: Twilio's test credentials accept a request without delivering it, and Firebase's Authentication emulator prints codes instead of texting them. Mock SMS gateways that capture outgoing messages in a web inbox do the same job for a shared staging environment.
These tests are fast, free and safe to run in parallel. They prove that your sign-in logic handles right, wrong, expired and repeated codes. They can't show that the live provider accepts your sender, that the message template still contains the code after someone edits it, or that a text reaches a phone in time.
Test real SMS delivery with a real phone number
For those questions, the application has to send a real text to a real number, and the test has to read it. MailSlurp gives your tests private phone numbers for that: you rent a number, give it to a test account, and read every text it receives through the API, a webhook or the dashboard. No physical phone or shared SIM is involved, and no one else can read the codes.
A typical test captures the time, triggers the code, waits for the new message on that number and completes the sign-in. With Playwright and the MailSlurp SDK:
import { test, expect } from "@playwright/test";
import { MailSlurp } from "mailslurp-client";
const mailslurp = new MailSlurp({ apiKey: process.env.MAILSLURP_API_KEY! });
test("signs in with a real SMS code", async ({ page }) => {
const since = new Date();
await page.goto("/login");
await page.getByLabel("Email").fill(process.env.TEST_USER_EMAIL!);
await page.getByLabel("Password").fill(process.env.TEST_USER_PASSWORD!);
await page.getByRole("button", { name: "Send code" }).click();
const sms = await mailslurp.waitController.waitForLatestSms({
waitForSingleSmsOptions: {
phoneNumberId: process.env.MAILSLURP_PHONE_ID!,
unreadOnly: true,
since,
timeout: 60_000,
},
});
const code = /\b(\d{6})\b/.exec(sms.body ?? "")?.[1];
expect(code, "six-digit code in the SMS").toBeDefined();
await page.getByLabel("Code").fill(code!);
await page.getByRole("button", { name: "Verify" }).click();
await expect(page.getByText("Signed in")).toBeVisible();
});
The wait runs on MailSlurp's servers and returns as soon as the text arrives, so the test needs no sleep or retry loop. since ignores codes from earlier runs. Keep the measured delivery time with the result: a code that arrives after it expires is a failed sign-in even though the message was delivered.
Use the same approach in your test framework
The pattern is the same in every framework: trigger, wait on the assigned number, extract, submit, assert the signed-in state.
- Playwright: the Playwright SMS guide, and the runnable Playwright SMS two-factor example with a simulated and a real-number test.
- Cypress: the Cypress SMS guide uses the
cy.mailslurp()command; the Cypress SMS example runs a complete signup. - Selenium: the page object guide builds email and SMS verification with Selenium and TestNG.
- Without a browser: the receive SMS guide reads messages and waits for codes from any language with an SDK.
Send a test text to your number by hand
Before automating anything, you can check a number manually. Text it from your own phone, or trigger your app's verification with that number, and the message appears in the MailSlurp dashboard with its sender and arrival time. This is a quick way to confirm that your provider's route reaches the country and number type you chose.
Run SMS tests in CI
Email tests can create a new inbox for every run; phone numbers are rented, so several tests often share one. Two tests requesting codes on the same number at the same time can each read the other's code. Give each parallel worker its own number, lease numbers from a phone pool, or serialize the jobs that share a number.
Run the simulated suite on every pull request and the real-number tests before each release or nightly, since each run sends a real text. The email and SMS CI guide has a GitHub Actions workflow with a shared-number concurrency group, and shows how to keep codes out of build logs.
Choose the right test number
Match the number to what your users have. MailSlurp numbers are available in the United States, Canada, the United Kingdom, Australia, the Netherlands, Sweden, Finland, Estonia, Poland and Israel. In the US, UK and Australia you can choose a number filtered for non-VoIP lines, for senders that reject VoIP numbers. US toll-free numbers are available for testing toll-free sending; the toll-free SMS guide explains what's different about that route.
If your app sends from a short code, check that the number type you choose can receive from it in that country before relying on the test. The disposable phone numbers guide covers reusing numbers and keeping test state separate, and phone number pricing lists the current rental and message costs.
Common questions
What is SMS testing?
SMS testing checks that your application's text messages are correct, reach real phones in time and let users complete the action they're for, such as signing in with a one-time code. It combines fast simulated tests of your code with tests that receive real messages on real numbers.
Can I test SMS without a real phone number?
Yes, for your own code: a fake sender, a provider test mode or a mock SMS gateway lets tests read the code without delivering anything. To test delivery, the provider route and timing, you need a real number. A rented test number gives you one without a physical phone.
What is the best SMS testing tool?
Choose a tool that gives your tests private real numbers in the countries you send to, an API that waits for the new message, and a way to run it from your test framework and CI. MailSlurp provides those for SMS and email in one API, so a sign-in test can check a text message code and an email link in the same run.
How do I automate SMS testing?
Assign a number to a test account, trigger the message from your app, wait for it with the API, extract the code and finish the action in your test. Keep one number per parallel worker, and run the real-number tests on a schedule as well as in your release pipeline.
Can I test toll-free and international SMS?
Yes. Rent a number of the type and country you send to, such as a US toll-free number or a UK mobile number, and run the same test against it. Each route can behave differently, so test the ones your users depend on.