Saturday 2:35 p.m.–3:05 p.m.
Unit Testing Makes Your Code Better
- Audience level:
- Best Practices & Patterns
Unit testing is like public transit: everyone agrees it's a good thing for other people to do. It's easier to swallow when you see how unit testing improves not only the correctness of your code, but the design as well. I'll walk through a real-life case study where adding unit tests turned a pretty good module into an even better one: easier to understand, extend, and reuse.
Automated testing by developers has been *de rigeur* for more than a decade now -- or has it? Unfortunately, there are still too many organizations and too many developers that do not use automated testing in a rigorous, disciplined way. It's no surprise that writing tests makes your code more correct. I'm going to focus in particular on the lowest level of automated testing, unit testing, with the aim of explaining one of its unexected benefits: unit testing improves the design of your code. Cleaner code isn't just an intellectual exercise: it's code that is easier to understand, easier to modify, easier to extend, and easier to reuse. Regular use of unit tests will not merely help you to write more correct code; it will make you a better programmer.