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...
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 ...
Get Head First Ruby 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.