Chapter 13. Unit Testing: Code Quality Assurance
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.
Unit tests are the most common, most important type of automated test. And Ruby includes MiniTest, a library devoted to unit testing. This chapter will teach you everything you need to know about it!
Automated tests find your bugs before someone else does
Developer A runs into Developer B at a restaurant they both frequent...
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?
Your automated tests. They didn’t fail when the bug got introduced?
Um, we don’t have any of those.
Your customers rely on your code. When ...