Testing Microservices with Mountebank
Brandon Byars
  • MEAP began March 2017
  • Publication in November 2018 (estimated)
  • ISBN 9781617294778
  • 240 pages (estimated)
  • printed in black & white

Byars tells all you need to know to get microservice testing up and running efficiently and effectively.

Bonnie Bailey, Motorola Solutions
Testing Microservices with Mountebank is your guide to the ins and outs of testing microservices with service virtualization. Starting from your first test with mountebank you'll dive into testing with canned responses, using predicates, and recording and replaying behavior to your tests. Following real world use-cases you'll master the art of programming mountebank with your own dynamic responses and explore working with binary protocols. This book also explains using mountebank for load testing, in a continuous delivery pipeline, and more.
Table of Contents detailed table of contents



About this Book

Who should read this book

How this book is organized

About the code

Author Online

Online Resources

About the Author

Part 1: First Steps

1 Testing Microservices

1.1 A microservices refresher

1.1.1 The path towards microservices

1.1.2 Microservices and organizational structure

1.2 The problem with end-to-end testing

1.3 Understanding service virtualization

1.3.1 Test-by-test setup using an API

1.3.2 Using a persistent data store

1.3.3 Record and replay

1.4 Introducing mountebank

1.5 The service virtualization tool ecosystem

1.6 Summary

2 Taking Mountebank for a Test Drive

2.1 Setting up the example

2.2 HTTP and mountebank: a primer

2.3 Virtualizing the Product Catalog Service

2.4 Our First Test

2.5 Summary

Part 2: Using mountebank

3 Testing Using Canned Responses

3.1 The Basics of Canned Responses

3.1.1 The Default Response

3.1.2 Understanding how the default response works

3.1.3 Changing the default response

3.1.4 Cycling through responses

3.2 HTTPS imposters

3.2.1 Setting up a trusted HTTPS imposter

3.2.2 Using mutual authentication

3.3 Saving the responses in a configuration file

3.3.1 Saving multiple imposters in the config file

3.4 Summary

4 Using Predicates to Send Different Responses

4.1 The basics of predicates

4.1.1 Types of predicates

4.1.2 Matching object request fields

4.1.3 The deepequals predicate

4.1.4 Matching multi-valued fields

4.1.5 The exists predicate

4.1.6 Conjunction Junction

4.1.7 A complete list of predicate types

4.2 Parameterizing predicates

4.2.1 Making case-sensitive predicates

4.3 Using predicates on JSON values

4.3.1 Using direct JSON predicates

4.3.2 Selecting a JSON value with JSONPath

4.4 Selecting XML values

4.5 Summary

5 Adding record / replay behavior

5.1 Setting up a proxy

5.2 Generating the correct predicates

5.2.1 Creating predicates with predicateGenerators

5.2.2 Adding predicate parameters

5.3 Capturing multiple responses for the same request

5.4 Ways to replay a proxy

5.5 Configuring the proxy

5.5.1 Using mutual authentication

5.5.2 Adding custom headers

5.6 Proxy use cases

5.6.1 Using a proxy as a fallback

5.6.2 Converting HTTPS to HTTP

5.7 Summary

6 Programming mountebank

6.1 Creating your own predicate

6.2 Creating your own dynamic response

6.2.1 Adding state

6.2.2 Adding async

6.2.3 Deciding between response vs. predicate injection

6.3 A word of caution: security matters

6.4 Debugging tips

6.5 Summary

7 Adding behaviors

7.1 Understanding behaviors

7.2 Decorating a response

7.2.1 Using the decorate function

7.2.2 Adding decoration to saved proxy responses

7.2.3 Adding middleware through shellTransform

7.3 Adding latency to a response

7.4 Repeating a response multiple times

7.5 Replacing content in the response

7.5.1 Copying request data to the response

7.5.2 Looking up data from an external data source

7.6 A complete list of behaviors

7.7 Summary

8 Protocols

8.1 How protocols work in mountebank

8.2 A TCP primer

8.3 Stubbing text-based TCP-based RPC

8.3.1 Creating a basic TCP imposter

8.3.2 Creating a TCP proxy

8.3.3 Matching and manipulating an XML payload

8.4 Binary support

8.4.1 Using binary mode with Base64 encoding

8.4.2 Using predicates in binary mode

8.5 Virtualizing a .NET Remoting service

8.5.1 Creating a simple .NET Remoting client

8.5.2 Virtualizing the .NET Remoting server

8.5.3 How to tell mountebank where the message ends

8.6 Summary

Part 3: Closing the Loop

9 Mountebank and Continuous Delivery

9.1 A continuous delivery refresher

9.1.1 Test strategy for continuous delivery with microservices

9.1.2 Mapping your test strategy to a deployment pipeline

9.2 Creating a test pipeline

9.2.1 Creating unit tests

9.2.2 Creating service tests

9.2.3 Balancing service virtualization with contract tests

9.2.4 Exploratory testing

9.3 Summary

10 Performance testing with mountebank

10.1 Why service virtualization enables performance testing

10.2 Defining your scenarios

10.3 Capturing the test data

10.3.1 Capturing the responses

10.3.2 Capturing the actual latencies

10.3.3 Simulating wild latency swings

10.4 Running the performance tests

10.5 Scaling mountebank

10.6 Summary

About the Technology

Microservices are independent, single-responsibility units of code that form a system with other microservices. It's difficult to test an individual microservice since each one depends on the other services. Mountebank solves this conundrum through service virtualization - imitating other components in the system so that you can test a microservice in isolation. Mountebank is the most capable service virtualization tool around, providing a programmable stand-in for a real dependency. As the only open-source virtualization tool with support for multiple protocols and scaling for load testing mountebank isn't snake oil; it's the cure-all for all your service virtualization needs.

What's inside

  • Approaches to service virtualization
  • Testing using canned responses
  • Programming mountebank
  • Understanding behaviors
  • Creating record / replay behavior
  • Adding contract tests

About the reader

Readers need programming skills and should be generally familiar with SOA or microservice systems.

About the author

Brandon Byars is a principal consultant at ThoughtWorks with long-standing experience in SOA and microservices. He is the author and chief maintainer of Mountebank and has helped multiple companies use it for testing a variety of systems.

Manning Early Access Program (MEAP) Read chapters as they are written, get the finished eBook as soon as it’s ready, and receive the pBook long before it's in bookstores.

FREE domestic shipping on three or more pBooks

A complete and practical introduction to Service Virtualization using mountebank, with lots of usable examples.

Alain Couniot, Head of Enterprise Architecture at STIB-MIVB

It’s going to make easier to test your microservices - Maintain your microservices’ tests doesn’t need to be hard!

Alessandro Campeis, Senior software engineer at Vimar SpA

Before reading this book I had no idea that we can actually mock complex services for unit testing. This is a wonderful book—a must read for all Software Architects.

Tiklu Ganguly, CTO at Mazik Global