Testing has always been a part of software development. For decades, comprehensive testing was defined by complex manual test procedures backed by big budgets; but something revolutionary happened in 1998. In his Guide to Better Smalltalk, Smalltalk guru Kent Beck introduced an automated test framework called SUnit. This triggered an avalanche of test frameworks including JUnit, PyUnit, and many others for different languages and various platforms, dubbed the xUnit movement. Automated testing was made a cornerstone of the agile movement when 17 top software experts signed the Agile Manifesto in 2001.
Testing includes many different styles including unit testing, integration testing, acceptance testing, smoke testing, load testing, and countless others. This book digs in and explores testing at all the important levels while using the nimble power of Python. It also shows many tools.
This book is meant to expand your knowledge of testing from something you either heard about or have practiced a little into something you can apply at any level to meet your needs in improving software quality. I hope to give you the tools to reap huge rewards in better software development and customer satisfaction.
Chapter 1, Using Unittest to Develop Basic Tests, gives you a quick introduction to the most commonly used test framework in the Python community.
Chapter 2, Running Automated Tests with Nose, introduces the most ubiquitous Python test tool and gets busy by showing how to write specialized plugins.
Chapter 3, Creating Testable Documentation with doctest, shows many different ways to use Python's docstrings to build runnable doctests as well as writing custom test runners.
Chapter 4, Testing Customer Stories with Behavior Driven Development, dives into writing easy-to-read testable customer stories using doctest, mocking, and Lettuce/Should DSL.
Chapter 5, High Level Customer Scenarios with Acceptance Testing, helps you get into the mindset of the customer and write tests from their perspective using Pyccuracy and the Robot Framework.
Chapter 6, Integrating Automated Tests with Continuous Integration, shows how to add continuous integration to your development process with Jenkins and TeamCity.
Chapter 7, Measuring your Success with Test Coverage, explores how to create coverage reports and interpret them correctly. It also digs in to see how to tie them in with your continuous integration system.
Chapter 8, Smoke/Load Testing—Testing Major Parts, shows how to create smoke test suites to get a pulse from the system. It also shows how to put the system under load to make sure it can handle the current load as well as finding the next breaking point for future loads.
Chapter 9, Good Test Habits for New and Legacy Systems, shows many different lessons learned from the author about what works when it comes to software testing.
You will need Python 2.6 or above. The recipes in this book have NOT been tested against Python 3+. This book uses many other Python test tools, but includes detailed steps to show how to install and use them.
This book is for Python developers who want to take testing to the next level. It covers different styles of testing, giving any developer an expanded set of testing skills to help write better systems. It also captures lessons learned from the author, explaining not only how to write better tests but why.
In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.
Code words in text are shown as follows: "Create a new file called recipe1.py
to store all of this recipe's code."
A block of code is set as follows:
def test_parsing_millenia(self): value = RomanNumeralConverter("M") self.assertEquals(1000, value.convert_to_decimal())
When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:
if __name__ == "__main__":
unittest.main()
New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "The unittest module provides a convenient way to find all the test methods in a TestClass".
Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.
To send us general feedback, simply send an e-mail to <[email protected]>
, and mention the book title via the subject of your message.
If there is a book that you need and would like to see us publish, please send us a note in the SUGGEST A TITLE form on www.packtpub.com or e-mail <[email protected]>
.
If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.
Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.
You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the files e-mailed directly to you.
Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/support, selecting your book, clicking on the errata submission form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded on our website, or added to any list of existing errata, under the Errata section of that title. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support.
Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.
Please contact us at <[email protected]>
with a link to the suspected pirated material.
We appreciate your help in protecting our authors, and our ability to bring you valuable content.
You can contact us at <[email protected]>
if you are having a problem with any aspect of the book, and we will do our best to address it.1