Testing an OTP flow looks simple until you try to automate it. You trigger a code, wait for an SMS, type it in, and move on — but in a real test suite that manual step breaks everything. You need a fresh number, a way to read the message programmatically, and a repeatable setup that does not depend on someone's personal phone.
That is where a temporary virtual number and a REST API help. In this guide I will walk through a practical workflow using OtpMango as the example, because it covers the pieces this kind of testing needs: real-SIM, non-VoIP numbers, an API you can poll from a test script, and numbers for 2,400+ apps.
The problem with testing OTPs on a personal phone
- You cannot parallelize it. One phone can only receive one code at a time, so concurrent tests queue up or collide.
- Numbers get reused. If the same number is tied to an old test account, your new test may hit "account already exists" instead of the flow you actually want to test.
- VoIP numbers get rejected. Many services filter out VoIP ranges. A real-SIM, non-VoIP number is far more likely to be accepted for SMS verification in the first place.
- Manual steps hide flakiness. If a human reads the code and types it in, you never learn whether your app's timeout, resend logic, or error messages actually work.
The fix is to treat the phone number as a test fixture: rent it, use it, read the SMS through the API, assert on the result, and let it expire.
A repeatable workflow
1. Rent a number for the country and app you are testing
Pick the country your test scenario needs. OtpMango offers temporary numbers in the USA, UK, Canada, Hong Kong, Indonesia, and Australia, among others. Match the country to the app and the phone format your form expects — a US test that fills in a UK number will fail for the wrong reason and waste a debugging cycle.
Also check that the number supports the app you are testing. With 2,400+ supported apps, the practical step is the same either way: search for your target app before you rent, and rent only when it is listed.
Pricing is pay per number, from $0.02, with no subscription. That matters for test budgeting: you can cost a suite as "numbers used" rather than carrying a monthly plan you only need during a release week.
2. Trigger the OTP from your own app
Start the flow exactly as a user would — in your own staging or development environment, against an account you own or a test account your team created for this purpose. Enter the rented number, submit the form, and let your app send the code.
Do not use this setup to test accounts you do not own, and do not use temporary numbers for banking or other high-stakes production accounts. This workflow is for testing your own OTP implementation.
3. Poll for the SMS through the API
Instead of watching a phone, poll the API for the latest message on that number. A simple polling loop is usually enough:
// Illustrative polling logic — check the OtpMango docs // for the exact endpoint and response shape. async function waitForSms(numberId, timeoutMs = 120000) { const startedAt = Date.now(); while (Date.now() - startedAt < timeoutMs) { const messages = await apiClient.getMessages(numberId); const latest = messages[0]; if (latest) return extractCode(latest.text); // e.g. /\b\d{4,6}\b/ await sleep(5000); } throw new Error("No SMS received within the timeout"); } The API allows 120 requests per minute, so polling every 5 seconds uses about 12 requests per minute — comfortably inside the limit. Polling every second is not only unnecessary, it also makes your logs noisy and your tests harder to read. Use a steady interval, add a clear timeout, and fail the test loudly when nothing arrives instead of waiting forever.
4. Assert on the code, not just on delivery
Receiving an SMS is only half the test. Assert the things your users will actually hit:
- The code has the expected format and length (usually 4–6 digits).
- Entering the correct code signs the test user in or completes the step.
- Entering a wrong code shows a clear error and does not advance the flow.
- An expired code is rejected, not silently accepted.
- Requesting a resend respects your throttling rules and does not spam the number.
Keep the code out of your test logs. Log that a code was received and that the assertion passed, not the code itself.
5. Mind the session window
Each rented number comes with a 360-minute session — six hours. That is generous for a single test run, but plan around it:
- Run short suites against one number per test case, not one number for the whole day.
- If a long regression suite runs past the window, rent a fresh number for the next batch instead of debugging a number that has already expired.
- Clean up test accounts and data after the run so a later test does not inherit state from this one.
A checklist for a solid OTP test suite
- Happy path: correct code, first try, completes the flow.
- Wrong code: clear error, no access granted, retry still possible.
- Expired code: old code rejected after its validity window.
- Resend: resend works, but is rate-limited as designed.
- Timeout: the UI handles "no SMS yet" gracefully instead of hanging.
- Concurrency: two tests running at once do not read each other's codes — use one number per test.
- Cleanup: the test account and number are released or expired, and no secrets leak into logs.
Common mistakes to avoid
- Reusing one number for every test. It creates cross-test interference and makes failures hard to reproduce.
- Polling too aggressively. Respect the 120 req/min limit; a 5–10 second interval is plenty for SMS delivery.
- Hard-coding the code. If your test only passes with a fixed code, it is not testing the OTP flow at all.
- Testing against production. Use staging or a dedicated test environment, with test accounts you control.
- Ignoring the country format. Validate the number format your form expects before you blame the SMS provider.
When this approach fits — and when it does not
This approach fits QA automation, staging checks before a release, and debugging a specific OTP failure ("did the code arrive, or did our app mishandle it?"). It is a way to make an unreliable manual step deterministic.
It does not fit production accounts, account recovery for accounts you do not own, or anything that needs a permanent, trusted phone number. A temporary number is a test fixture, not an identity.
Wrapping up
A good OTP test is boring in the best way: rent a number, trigger the code, read it through the API, assert the behavior, and move on. With real-SIM, non-VoIP numbers, a 360-minute session, and an API you can poll at a sane rate, you can cover the happy path and the edge cases without a drawer full of test phones.
If you want to try this workflow, you can rent a temporary number on OtpMango and run the checklist above against your own staging environment. Start with one flow, get it green and repeatable, then expand to the edge cases — that is usually where the real bugs are.



