How to Test User Receiving a Text – Unit and Functional Testing

functional-testingunit testing

I am writing functional tests for my application that scrapes some data online then sends the results in an SMS text (on a weekly basis). My understanding is that functional tests are meant to test the functionality from the users' point of view. So, how do I "test" that the user receives a text? I am using Twilio API. Also, how do I test that the user is receiving the text weekly? Am I thinking about this wrong?

Best Answer

You're using a third-party API, so you don't need to spend a lot of effort to automate testing the functionality provided by that API. You need to focus testing on your application's interactions with that API.

One set of tests can be written against the API documentation. Looking at the documentation, what are the valid responses from the API? If you mock out the third-party API and replace it with mock responses, does your system behave as expected given the response?

Another set of tests can used captured actual responses from the API and ensure that your system is handling the actual messages. You could combine this with the first approach, as well and capture real responses in different sets of success and failure cases and use those in testing.

Some APIs also have test credentials. It appears that Twilo provides this. In some cases, they may have different, test-specific endpoints that they maintain to allow you to test different scenarios and get simulated responses. This can also be useful in test or other demonstration environments.

You should have monitoring and logging (of the parameters to and responses from) the third-party API. You can perform some manual testing in a pre-production environment, probably using the test credentials. Monitoring in the production environment can also provide information to report defects to the vendor.

Related Topic