Testing Java Microservices

Microservices continue to gain ground in enterprises due to the benefits for which they have been most promoted: reduced size, loose coupling, and the composability they enable. IT managers have begun to understand that service-based computing is not the same as the service-oriented architecture (SOA) popular at the turn of the century. As microservices gain traction, however, there has arisen the nettlesome problem of testing them.

Testing Java Microservices aims to provide a solution to this problem by examining a small ecosystem of tools based on Arquillian. The latter is a container-agnostic testing framework designed to test services as a producer (does it work correctly internally?), as a consumer (how does it function when used as a REST service?), and as a client (by driving browser activity). The distinguishing element of Arquillian is the ability to run your microservices and then execute tests against them. It can drive unit tests and integration tests, and it understands containers, virtualization, and fundamental problems of a testing environment, such as using a separate classpath. (Note that Arquillian was originally a framework for testing apps running in a Java EE container. Its most recent versions have added Spring support and the ability to work with Docker containers.)

The authors, who are strongly connected to Arquillian, are at pains to include coverage of tools other than Arquillian. And they introduce some notable tools—in particular Pact, which is a family of test frameworks for verifying consumer-side contract testing. The authors also integrate testing with familiar products, such as JUnit and Mockito. In this sense, the book serves as a reasonable overview of testing microservices. However, everything is still fundamentally tied to Arquillian and its way of doing things. As a result, other useful tools such as mountebank, which provides over-the-wire test doubles, are not mentioned at all, even though mountebank would be an important resource to know about. (The authors do cover a similar resource, Hoverfly, which is briefly introduced and explained in the book.)

A final chapter covers the crucial topic of setting up the microservice tests to run in a continuous-delivery pipeline. This step is easy to overlook because of its complexity, leading the final delivered service to be tested only in isolation.

Overall, Testing Java Microservices is a good introduction to the issues of testing microservices that run on the JVM (they need not be written in Java as the title would imply). However, its greatest value is to organizations that are evaluating Arquillian or are already committed to its use as their primary microservices testing framework.

Andrew Binstock

Andrew Binstock (@platypusguy) was formerly the editor in chief of Java Magazine. Previously, he was the editor of Dr. Dobb's Journal. He co-founded the company behind the open-source iText PDF library, which was acquired in 2015. His book on algorithm implementation in C went through 16 printings before joining the long tail. Previously, he was the editor in chief of UNIX Review and, earlier, the founding editor of the C Gazette. He lives in Silicon Valley with his wife. When not coding or editing, he studies piano.