Friday, May 12, 2017

Test mocks are definitely worth it

I'm currently working on an application that interacts with a system outside the machine it runs on - specifically, it sends and receives text messages through an Internet SMS gateway. That gets rather unwieldy in test environments, since obviously I can't use real people's data, and I only have one or two phones available to me at any given time. Besides, using the SMS gateway costs money.

It used to take me a while to get the SMS gateway connected for tests, and waiting for the texts to go through one direction and back the other also took up several moments, but it was never too much of an inconvenience. Then one day while planning a large round of tests on new features, I decided to finally sit down and write a mock for the gateway. Instead of actually sending the texts out to the Internet, this message provider (a drop-in replacement for the real library) just puts them up in a window. Instead of me needing to text back on a phone, I just type the "from" number and the text into some fields and click a button.

This is fast and exceptionally convenient compared to the old system. I wasn't sure before creating it whether it would be worthwhile, but it unquestionably was. Of course, this presupposes an architecture that allows easy drop-in replacement of the component being mocked, but if you have that infrastructure, strongly consider making a test mock.

No comments:

Post a Comment