Testing Java Applications for Resilience by Simulating Network Problems with Toxiproxy, JUnit and the Docker Maven Plugin

When implementing distributed systems, client-server architectures and simple applications with network related functionalities, everything is fine when we’re in the development or in the testing stage because the network is reliable and the communicating systems are not as stressed as they are in production. But to sleep well we want to validate how resilient we have implemented our systems, how they behave when the network fails, the latency rises, the bandwidth is limited, connections time out and so on. ...

July 29, 2018 · 9 min · 1836 words · Micha Kops

Setting up Kafka Brokers for Testing with Kafka-Unit

When writing test for applications that interact with Kafka brokers we often need to setup a decent environment including an instance of Kafka and ZooKeeper. Though Kafka ships with some classes for testing, setting up a simple testing environment is quite easier with the kafka-unit library that offers JUnit test rule support or a fast programmatic setup within no time. In the following short example, I’d like to show how create a simple setup using Maven, Surefire and kafka-unit. ...

March 28, 2018 · 4 min · 825 words · Micha Kops

Handling System Properties, Environment Variables, STDOUT/STDERR in JUnit Tests with System Rules

When important data is written to STDIN/STDOUT and an application relies on specific system properties or environment variables, writing tests is getting more complicated. System Rules is a collection of JUnit rules that helps us writing Java tests for everything that deals with java.lang.System. In the following short examples I’d like to demonstrate how to deal with system properties, environment variables, STDOUT and STDERR and capturing both for testing e.g. for some golden master refactoring. ...

December 19, 2016 · 4 min · 718 words · Micha Kops

Ordering your JUnit Rules using a RuleChain

JUnit Rules are a handy solution if one needs to alter test methods or wants to share common functionality between several test cases. JUnit 4.10 introduced a new class to order several rules according to our needs using a so called rule-chain. In the following example, we’re going to create a simple custom rule and afterwards bind several instances of it in a specified order to a test method. Adding JUnit Just one Maven dependency needed here – JUnit 4.10 ...

February 21, 2012 · 3 min · 560 words · Micha Kops