Book Image

Test-Driven Python Development

By : Siddharta Govindaraj
Book Image

Test-Driven Python Development

By: Siddharta Govindaraj

Overview of this book

This book starts with a look at the test-driven development process, and how it is different from the traditional way of writing code. All the concepts are presented in the context of a real application that is developed in a step-by-step manner over the course of the book. While exploring the common types of smelly code, we will go back into our example project and clean up the smells that we find. Additionally, we will use mocking to implement the parts of our example project that depend on other systems. Towards the end of the book, we'll take a look at the most common patterns and anti-patterns associated with test-driven development, including integration of test results into the development process.
Table of Contents (20 chapters)
Test-Driven Python Development
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Integrating with continuous integration tools


Continuous integration tools allow us to validate the integrity of our application by running the test suite on every commit. We can configure them to raise an alert if any of the tests are failing, or even if the test coverage level drops too low.

Jenkins

Jenkins is a popular Java-based continuous integration system. Integrating with Jenkins requires the nose2 runner because we will need to get output in an XML format.

The first thing we need to do is to configure Jenkins to run the unit tests as a part of the build. To do this, we add a shell step to the build and enter the command to run the tests. We need to enable the JUnit XML plugin and get coverage in XML format, as shown in the following screenshot:

We then need to tell Jenkins where to find the unit test results. Select the Publish JUnit test result report checkbox and enter the location of the nose2 unit test XML file, as shown in the following screenshot:

Enable the Publish Cobertura Coverage...