Writing Tests for Autonomous Components

Basically every test, microservices or not, is a three-step dance:

  1. Set up the data for the test.
  2. Exercise the (sub)system under test.
  3. Make assertions about the results.

How does that work with autonomous components? Well, let’s consider one of the very first autonomous components you wrote back in Writing Your First Aggregator, the home page Aggregator. Its job was and still is to turn video view events into an aggregated global view count. Side by side with every bit of code in this book are test files. They’re the ones that end in .test.js. The test for the home page Aggregator is no exception. Let’s break down the basic skeleton of a test file:

 const ...

Get Practical Microservices now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.