Component Tests for Spring Cloud Microservices

Introduction

The shift towards microservices has a direct impact on the testing strategies applied and has introduced a number of complexities that need to be addressed. In fact, microservices require additional levels of testing since we have to deal with multiple independently deployable components.

An excellent explanation of these concepts and the various levels of microservices testing is given by Martin Fowler in his Testing Strategies in a Microservice Architecture presentation. Let's have a look at the revised "test pyramid" from this presentation:

Custom appsettings.json File for ASP.NET Core Integration Tests

ASP.NET Core introduced the concept of TestServer for the integration testing of web applications. Integration tests need web applications to run with all the bells and whistles to make sure that all the components work together with no flaws. Often we need special settings for integration tests as web applications cannot use live services and the easiest way to do it is to use a special appsettings.json file. This blog post shows how to do it.

Getting Started

Let's start with minimalistic integration test from ASP.NET Core integration tests document.

Unit Tests Vs. Integration Tests: Battle Continues

One would expect that after being in the industry for almost 20 years, a trivial comparison like this would be years behind me, but I am probably less than correct. It seems that the right amount of unit tests is still a burning issue that needs some attention. At Knoldus, we have the policy of maintaining a very high code coverage so that we can objectively validate the quality of the code through our now publicly available tool CodeSquad.

We place a very high premium on writing very very effective unit tests. However, a recent discussion with one of our esteemed clients made us rethink this strategy. Let us be clear though that we do not believe that we should not be writing unit tests but the distribution between the unit and integration tests, the scenarios in which we can skip unit tests do need a review. The following is an attempt to do that:

Testing Spring Boot Integration With Vault and Postgres Using Testcontainers Framework

I have already written many articles where I was using Docker containers for running some third-party solutions integrated with my sample applications. Building integration tests for such applications may not be an easy task without Docker containers. Especially if our application integrates with databases, message brokers, or some other popular tools. If you are planning to build such integration tests, you should definitely take a look on Testcontainers.

Testcontainers is a Java library that supports JUnit tests, providing a fast and lightweight way for running instances of common databases, Selenium web browsers, or anything else that can run in a Docker container. It provides modules for the most popular relational and NoSQL databases like Postgres, MySQL, Cassandra, or Neo4j. It also allows running popular products like Elasticsearch, Kafka, Nginx, or HashiCorp's Vault. Today, I'm going to show you a more advanced sample of JUnit tests that use Testcontainers to check out an integration between Spring Boot/Spring Cloud application, Postgres database, and Vault.