
Otherwise problems will arise when going for production deploy. You should keep a small gap between your production and your development environments. As services get smaller, integration with the infrastructure becomes a bigger part of the job. A given API component relies on more external parts (infrastructure or other APIs). What about just running unit tests instead?įor the last 10 years, large monolith applications have been split into smaller services (trending towards the buzzy "microservices"). You might wonder if it isn't overkill to perform end to end tests at all with Docker compose. This allows you to run several of them in parallel on your local computer or a CI host. Docker compose will also create an isolated network for all the containers for a given test run.

Our API thinks it is in a real physical environment. It is mocking but on the outside of our code. It creates "containerized" versions of all the external parts we use. Having a shared database, you can run only 1 test at a time to ensure test runs do not interfere with each other.ĭocker Compose allows us to get the best of both worlds. It is a lot of setup and maintenance, and it does not scale. Running the thing in a real server is infrastructure heavy. It is also often not very representative of how the API will behave in production.
Docker for mac in use can't quit code#
Mocking everything at code level clutters the code and configuration of our API. You can mock the environment at code level or run the tests on a real server with the database etc. To test your API in a close to production environment you have two choices. You can skip it if you want to get to the technical part right away. This section contains a lot of arguments in favour of using Docker for testing. You'll use different Docker base images to run whatever component you might need. The principles applied in this article will remain the same. Your API might need a different environment.

Our API will use other external APIs to do its job.We are going to use a pretty standard environment for the API: It's more than enough to grasp the concept and apply to the more complex business logic of your API. The example will cover a simple set of CRUD endpoints for users. Keep reading even if Javascript makes you sick. The principles applied are valid for any tech stack. I've chosen a JS'y stack because the code is super short and easy to read. In this article we are going to test an API built with Node/express and use chai/mocha for testing.
Docker for mac in use can't quit how to#
Let's see how to achieve this with not that much effort.

Having tests because everybody says "you should have tests" is no good if it slows you down. They should boost your productivity and improve the quality of your software. It means tests that are useful to you as a developer on a day-to-day basis. We want fast, meaningful and reliable tests written and maintained with minimal effort. In this article you'll see how you can engineer tests for yourself with Docker. Sometimes tests are there but very long to run or unstable. Some see it but think of it as an extra step slowing them down.
