Sitemap
Charith Ellawala

Charith Ellawala

Go Integration Testing Techniques

1 min readOct 27, 2018

--

In an ideal world, all tests are hermetic and we are able to capture all possible behaviours of external systems within our testing code. In reality, however, this often requires prescient knowledge about the external system and the complicated tangle of variables that affect the interaction between the two systems. Even if such knowledge was available, the work required to emulate that behaviour would often dwarf the effort required to deliver the project.

Get Charith Ellawala’s stories in your inbox

Join Medium for free to get updates from this writer.

In this post I describe two automated testing techniques that I employ when writing code that interacts with remote systems.

Using Dockertest to test interactions with popular software distributions

Dockertest is a fantastic library for programmatically launching Docker containers from testing code. For a simple example, let’s assume our code needs to interact with a Redis server. Instead of writing code/scripts to launch a Redis instance and reset its state on every test invocation — which can often result in brittle, unportable code — we can utilize the ubiquitous Docker installations found on most dev and CI machines to launch a dedicated Redis container for the duration of our tests.

Resilliency testing with Toxiproxy

Toxiproxy is a TCP proxy service that can be controlled programmatically to simulate various network conditions. This is an invaluable tool for testing distributed systems such as IoT servers that need to operate under unpredictable and poor network conditions.

In the following example, we are testing a gRPC service under various network conditions.

--

--