Chapter 7. Automated Testing
Writing automated tests is one of those things that separates average developers from the best in the world. Master this skill, and you will be able to write far more complex and powerful software than you ever could before. It is a superpower that changes the arc of your career.
Some of you have, so far, little or no experience writing automated tests, in any language. This chapter is primarily written for you. It introduces many fundamental ideas of test automation, explains the problems it is supposed to solve, and teaches how to apply Python’s tools for doing so.
Some of you will have extensive experience using standard test frameworks in
other languages (such as JUnit in Java, PHPUnit in PHP, and so on). Generally
speaking, if you have mastered an xUnit framework in another language,
and are fluent in Python, you may be able to start skimming Python’s unittest
module
docs1
and be productive in minutes. Python’s test library, unittest
, maps
closely to how most xUnit libraries work.2
If you are more experienced, I believe it is worth your time to at least skim this chapter, and perhaps study it thoroughly. I have woven in useful, real-world wisdom for software testing in general, and for Python specifically. This includes topics like how to organize Python test code, writing maintainable test code, useful features like subtests, and even cognitive aspects of programming…like getting into an enjoyable, highly productive “flow” state via ...
Get Powerful Python 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.