O'Reilly logo

Using Docker by Adrian Mouat

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 8. Continuous Integration and Testing with Docker

In this chapter, we’re going to look into how Docker and Jenkins can be used to create a continuous integration (CI) workflow for building and testing our application. We’ll also take a look at other aspects of testing with Docker and a brief look at how to test a microservices architecture.

Testing containers and microservices brings a few different challenges to testing. Microservices make for easy unit tests but difficult system and integration tests due to the increased number of services and network links. Mocking of network services becomes more relevant than the traditional mocking of classes in a monolithic Java or C# codebase. Keeping test code in images maintains the portability and consistency benefits of containers, but increases their size.

Tip

The code for this chapter is available from this book’s GitHub. The tag v0 is the identidock code as it was at the end of the last chapter, with later tags representing the progression of the code through this chapter. To get this version of the code:

$ git clone -b v0 \
https://github.com/using-docker/ci-testing/
...

Alternatively, you can download the code for any tag from the Releases page on the GitHub project.

Adding Unit Tests to Identidock

The first thing we should do is add some unit tests to our identidock codebase. These will test some basic functionality of our identidock code, with no reliance on external services.1

Start by creating the file identidock/app/tests.py ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required