Embracing tests

Let's talk about the code-writing process. When we are working on large monoliths, many people need to be notified every time that a new feature or bug fix is released. In extreme cases, the QA team needs to check the entire environment themselves to ensure that the new changes didn't affect the application's existing functionality. Imagine how time-consuming it would be to repeat this task for every release with multiple microservices. For this reason, you need to adopt testing as an essential part of your development process.

There are many different levels of testing. Let's take a look at the pyramid test introduced by Jason Huggins in 2005, which is shown in the following diagram:

Pyramid test

The tests that are part of the pyramid's base are easy and quick to write and execute. Running unit tests only takes a few minutes, and is useful to validate that isolated pieces of code work as expected. Integration tests, on the other hand, are useful to validate that the code works when it's interacting with external services, such as databases, third-party applications, or other microservices. These tests will take a few tens of minutes to run. Finally, end-to-end (e2e) tests help you to validate that the code works as expected from an end user perspective. If you're writing a REST API, the e2e tests will validate the HTTP response codes from your API using different data. These tests are usually slow, and they change all the time.

Ideally, all of your new features should go through all of these tests to verify that your code is working as expected before going into production. The more tests you write, the more confidence you will gain. After all, if you've covered all the possible scenarios, what could go wrong? To add to this, Michael Bryzek introduced the idea of testing in production (see https://www.infoq.com/podcasts/Michael-Bryzek-testing-in-production for more information). This helps you to assess whether your services are working by executing automated tasks or bots regularly to exercise the key parts of your systems in production.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.142.200.109