Computing Reviews
Today's Issue Hot Topics Search Browse Recommended My Account Log In
Review Help
Search
Python unit test automation : practical techniques for Python developers and testers
Pajankar A., Apress, New York, NY, 2017. 111 pp. Type: Book (978-1-484226-76-6)
Date Reviewed: Aug 31 2017

Automated unit testing is a crucial part of the agile and DevOps approaches to software creation and deployment. The ability to get code into production with great regularity (companies good at this may deploy code into production hundreds or thousands of times per day) requires that code is regularly and thoroughly tested as it is developed, and not just “thrown over the wall” into QA just before it is released. To achieve this result, it is necessary to write automated tests (since such thorough, regular testing simply cannot be done “by hand” by busy developers) that cover all common use cases (including erroneous use) and that give clear reports on what problems, if any, have been uncovered. A good test framework makes such a test suite easy to write and integrates well into build tools such as make and Jenkins.

Given the importance of automated testing to these contemporary development styles, Ashwin Pajankar’s book is a timely addition to the literature. He has written a nice introduction to unit test automation in Python, albeit one with several flaws. If one needs a succinct overview of this topic, this book will certainly do the job.

Pajankar surveys five main testing frameworks: doctest, a very elementary testing framework in which tests are written into Python comments; unittest, Python’s built-in, more sophisticated testing module; nose and nose2, two extensions of unittest; and finally pytest. As the author points out, doctest is too primitive a tool to use for continuous-integration-style development. Its tests are limited to comparing single examples against a known value--an important aspect of more sophisticated testing is the ability to test against random, unexpected input--but Pajankar is justified in using it to introduce the concept of unit testing, due to this very simplicity.

After describing the various pros and cons of unittest, nose, and nose2, Pajankar recommends pytest as the best choice, due to its wealth of features and compatibility with both unittest- and nose-style tests.

The first problematic thing that struck me about this book is that chapter 1 seems to be a very strange inclusion. The chapter is a very brief, high-level introduction to the Python programming language, aimed at someone who knows almost nothing about it. But, is that reader likely to buy a book called Python unit test automation as her first introduction to the language? Won’t that reader pick up something with a name like Beginning Python?

This book also includes a very large number of screen shots and copies of the output of running some command or other. Now, certainly, a bit of this can be useful. But I suggest that, say, for a series of very similar tests, it is enough to put in, “Here is an example of the output of test A,” and not also show the nearly identical output for tests B, C, D, and E.

There are also some minor technical problems in this work. For instance, Pajankar claims, “You must use [the verbose mode of doctest] because without it, the test will not produce any output unless it fails” (p. 25). However, in many cases, that outcome might be exactly what one wants: to produce output only on failure.

Another technical quibble is that Pajankar apparently does not understand the meaning of the “all” keyword in an __init__.py file. He asserts that one has to include a file in the “all” section of __init__.py to make it part of that directory’s package. But that is wrong: what including a file in “all” does is to make it imported when one writes “from package import *.”

Also, on page 57, Pajankar writes, “Many times, you might want to have a method that explicitly fails a test when it’s called.” But he does not offer any explanation of what those “many times” might be. For someone trying to learn how to write good tests, an example or two here would have been very valuable.

Despite this book’s shortcomings, it provides a clear introduction to the options available for Python unit test automation, while at the same time introducing many general points about what one needs in a testing framework. For anyone who has begun writing Python programs, but is unsure about how to write automated tests for those programs, this book provides excellent guidance on how to get started.

More reviews about this item: Amazon

Reviewer:  Eugene Callahan Review #: CR145516 (1711-0697)
Bookmark and Share
  Reviewer Selected
Featured Reviewer
 
 
Testing And Debugging (D.2.5 )
 
 
Python (D.3.2 ... )
 
Would you recommend this review?
yes
no
Other reviews under "Testing And Debugging": Date
Software defect removal
Dunn R., McGraw-Hill, Inc., New York, NY, 1984. Type: Book (9789780070183131)
Mar 1 1985
On the optimum checkpoint selection problem
Toueg S., Babaoglu O. SIAM Journal on Computing 13(3): 630-649, 1984. Type: Article
Mar 1 1985
Software testing management
Royer T., Prentice-Hall, Inc., Upper Saddle River, NJ, 1993. Type: Book (9780135329870)
Mar 1 1994
more...

E-Mail This Printer-Friendly
Send Your Comments
Contact Us
Reproduction in whole or in part without permission is prohibited.   Copyright 1999-2024 ThinkLoud®
Terms of Use
| Privacy Policy