Chapter 14. code quality assurance: Automated Testing

image

Are you sure your software is working right now? Really sure? Before you sent that new version to your users, you presumably tried out the new features to ensure they all worked. But did you try the old features to ensure you didn’t break any of them? All the old features? If that question makes you worry, your program needs automated testing. Automated tests ensure your program’s components work correctly, even after you change your code. Go’s testing package and go test tool make it easy to write automated tests, using the skills that you’ve already learned!

Automated tests find your bugs before someone else does

Developer A runs into Developer B at a restaurant they both frequent…

Developer A: Developer B:
How’s the new job going? Not so great. I have to head back into the office after dinner. We found a bug that’s causing some customers to be billed twice as often as they should be.
Ouch. How did that get onto your billing server? We think it might have gotten introduced a couple of months ago. One of our devs made some changes to the billing code then.
Wow, that long ago… And your tests didn’t catch it? Tests?
Your automated tests. They didn’t fail when the bug got introduced? Um, we don’t have any of those.
What?!

Your customers rely on your code. When it fails, it can be disastrous. Your company’s ...

Get Head First Go now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.