Even in this day and age, there will always be a time and a place for SMS. We still use it for interacting and transacting with the brands we love. Businesses send out bulk SMS messages on a daily basis, and they need to make sure that each one goes to the right phone number and contains the correct information. Automated SMS testing is there to get the job done.
What is SMS testing?
SMS (“Short Message Service”) is one of the most common forms of sending messages on a mobile device. An SMS message contains only text and is limited to 160 characters.
SMS testing is simply a way of verifying that your text messaging service is performing the way it should when you send messages containing things like updates and verification codes.
The practical uses of SMS testing are quite far-reaching. Testing can verify that SMS messages are timely delivered to recipients in time-sensitive scenarios like bank transactions. It can also be used to test SMS verifications like one-time passwords for two-factor authorisation. Should you have customers who schedule appointments with you, SMS testing can confirm that appointment reminders are going out as they should.
Pitfalls of manual SMS testing
Many businesses opt for manual testing of their SMS setup, but this strategy does present some real challenges. While manual SMS testing can identify issues, it does require human input to perform each step of a test without test scripting. This can be a very tedious process which introduces the potential for user error into the equation.
Even the most dedicated human tester can create errors in data by inputting the wrong information at the wrong time. Given the time-consuming nature of manual testing, the last thing anyone needs is to have to look for the needle in the haystack responsible for throwing off an otherwise flawless SMS notification process.
Manual SMS testing is further constrained by the number of human testers, phones, and phone numbers that you have to work with. For a large-scale test, you may be extremely limited by the number of devices you have available to test with. In addition, running repeat tests is very time-consuming, with human testers having to perform the same functions over and over again. Your testers may not be willing to use their own phone numbers for this kind of testing, and having to buy phones and numbers to complete the required number of tests can be quite costly.
SMS testing aims to provide confidence that SMS messages are being sent to the correct numbers and that each message’s contents is accurate for the given recipient. While we can accomplish this with manual testing, there’s a much better solution.
Automated SMS testing to the rescue
Automated testing requires testers to write scripts that will automate the functions that need to be performed. Once coding is complete and the program is working, the code can run repeat tests with much greater efficiency and without concern for user error. Testers can adjust or maintain code as test parameters change.
Every part of a test is then performed through automation tools and scripts. Automated tests can even perform real user simulations to emulate how a user may respond to an SMS. In addition to SMS, test automation can simulate image and voice-related testing. It can also simulate users in different places through location mocking. Amazingly, common testing frameworks can be used to simulate fingerprint testing and facial recognition!
Although there can be coverage limitations with manual testing, this is not the case for automated testing. You can be sure to get the number of test samples you require, as automated testing can attain much greater test coverage than can a manual tester.
Mailosaur’s SMS testing capability
Mailosaur’s service is designed specifically to write automated tests for both the [email]({{<ref "email-testing" >}}) and [SMS]({{<ref "sms-testing" >}}) messages you would send out. Since Mailosaur is built for these very purposes, it has all the tools you will need and not the ones you will not.
With Mailosaur, you can create SMS tests using popular frameworks such as [Cypress]({{<ref "blog/what-is-cypress" >}}), Robot Framework, and Selenium. It is also compatible with top programming languages like Python and Java using an SDK.
Mailosaur allows access to mobile phone numbers for testing that are dedicated to your organisation, so no one on your team will ever need to use their own mobile phone number for testing. It keeps all your test data and received messages in one place, allowing you to manage access to all those messages easily.
Writing your first SMS test
With an understanding of SMS testing down, let’s now create our first test. You’ll first need to pick your preferred framework. For the sake of this example, we’ll be choosing Cypress. If you don’t have Cypress set up, check out our [guide]({{<ref "docs/frameworks-and-tools/cypress" >}}) to getting started with this framework.
To use Cypress with Mailosaur, we’ll also need to install Mailosaur’s Cypress library onto our system.
In the example below, we assume that a user of our website is requesting a one-time password (OTP) for authentication purposes. Perhaps this person has set up two-factor authentication and needs a six-digit code to access the system.
The user goes to our website, clicks the “one-time password” link, and chooses to have the code sent via an SMS message to their cell phone. This user is a member of our site, and we already have their contact information on file.
When this request comes in, we would use the following code to verify our having received a request and what our software should do once we receive it. Let’s a look at the code:
// cypress/e2e/sample_sms_test.cy.js
describe('OTP test', () => {
const serverId = 'SERVER_ID'; // Replace SERVER_ID with an actual Mailosaur Server ID
const testNumber = '14026742019'
it('Gets an OTP code', () => {
cy.mailosaurGetMessage(serverId, {
sentTo: testNumber
}).then(sms => {
expect(sms.text.body).to.contain('One-time password for example.org:');
})
})
})
Our OTP test comes through Mailosaur’s SMS testing service. We first list the variables we need to assign. These are the server ID we were given when we signed up with Mailosaur, and the SMS number that Mailosaur generated for us: 14026742019
. We can generate multiple numbers with Mailosaur but need only one for this example.
Our last bit of code expects a request for a one-time password from our website (in this case, example.org
).
Although not shown here, we will also need to write a test for the interaction where a user requests an OTP code on our test site.
When we run our sample test above using Cypress, we get the following output:
Running: sample_sms_test.cy.js (1 of 1)
OTP test
✓ Gets an OTP code (668ms)
1 passing (1s)
(Results)
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Tests: 1 │
│ Passing: 1 │
│ Failing: 0 │
│ Pending: 0 │
│ Skipped: 0 │
│ Screenshots: 0 │
│ Video: true │
│ Duration: 1 second │
│ Spec Ran: sample_sms_test.cy.js │
└───────────────────────────────────────────────────────────────────────────────────
We see that our chunk of code did indeed correctly receive the request to send a one-time password to the mobile number listed above.
Mailosaur simplifies your SMS testing
Mailosaur is an excellent tool for setting up automated SMS testing. Get plugged into Mailosaur to verify your SMS messages are doing everything you need them to do.