Testing Java Microservices
Alex Soto Bueno, Jason Porter and Andy Gumbrecht
  • MEAP began July 2015
  • Publication in September 2017 (estimated)
  • ISBN 9781617292897
  • 325 pages (estimated)
  • printed in black & white

With traditional software unit tests, there's never a guarantee that an application will actually function correctly in the production environment. And when you add microservices, remote resources that are accessible over a network, into the mix, testing is more tricky. To make things even harder, microservices typically need to collaborate with additional network-based microservices, making testing even more challenging.

"Gives a thorough explanation with specific examples using real world technology."

~ Ethan A. Rivett

"Provides clear examples for how to write tests that make sure the services continue working together as the services evolve."

~ GonKiran Anantha

"This is highly technical book with lot of valuable examples. It skips the theory and jump right into action."

~ Anshuman Purohit

Table of Contents detailed table of contents

1. An Introduction to Microservices

1.1. Why use, and What are Microservices?

1.1.1. Why use Microservices?

1.1.2. What are Microservices?

1.2. Microservice Networks and Features

1.2.1. Microservice Networks

1.2.2. Microservice Features

1.3. Microservice Architecture

1.3.1. Resource Component

1.3.2. Business Domain Component

1.3.3. Remote Resources Component

1.3.4. Persistence Component

1.4. Microservice Unit Testing

1.4.1. Solitary Unit Tests

1.4.2. Sociable Unit Tests

1.5. Summary

2. Application Under Test

2.1. Architecture

2.1.1. Game Service

2.1.2. Comment Service

2.1.3. Video Service

2.1.4. Game Aggregator Service

2.1.5. Overall Architecture

2.2. Usage and Screenshots

2.3. Patterns Leveraged

2.3.1. Anatomy

2.3.2. ECB pattern

2.3.3. Miscellaneous Patterns

2.4. Things Out of Scope

2.5. Summary

3. Unit Testing Microservices

3.1. Unit Testing Techniques

3.1.1. Solitary Unit Tests

3.1.2. The Sociable Unit Tests

3.1.3. Test Doubles

3.1.4. Unit Testing Inside Microservices

3.2. Tools

3.2.1. JUnit

3.2.2. AssertJ

3.2.3. Mockito

3.2.4. Build Script Modifications

3.3. Writing Unit Tests for Gamer application

3.3.1. YoutubeVideoLinkCreator Test

3.3.3. Games test

3.3.4. GamesService test

3.3.5. GamesResource test

3.4. Reader Exercise

3.5. Summary

4. Component Testing Microservices

4.1. The Arquillian Testing Framework

4.2. Introducing The @RunWith(Arquillian.class) Annotation

4.3. The ShrinkWrap Utility Class

4.3.1. Building an Archive

4.3.2. Adding Content to the ShrinkWrap Archive

4.3.3. Adding Resources

4.3.4. Adding Libraries and Dependencies

4.3.5. The Maven Resolver

4.3.6. Adding a Service Implementation

4.3.7. Write Once and Reuse

4.4. Build Script Modifications

4.4.1. Maven

4.4.2. Gradle

4.5. Configuration

4.5.1. The Container

4.5.2. Container Properties

4.6. The Arquillian REST Extension

4.6.1. REST Client

4.6.2. Warp REST

4.7. Testing Spring Applications

4.7.1. Arquillian Spring Framework Extension

4.7.2. Spring Boot

4.8. More Examples

4.8.1. Testing the Remote Component

4.8.2. Testing the Resource Component

4.8.3. Testing the Domain Component

4.8.4. Testing the Persistence Component

4.9. Reader Exercise

4.10. Summary

5. Integration Testing Microservices

5.1. Integration Testing Techniques

5.1.1. Integration Testing Inside Microservices

5.2. Tools

5.2.1. Arquillian Persistence Extension

5.2.2. NoSQLUnit

5.2.3. Arquillian Multideployment

5.2.4. Arquillian Sequence

5.2.5. Build Script Modifications

5.3. Writing Integration Tests for Gamer application

5.3.1. Games Test

5.3.2. Comments Test

5.3.3. Comments Gateway Test

5.4. Reader Exercise

5.5. Summary

6. Contract Tests

6.1. Consumer Contracts

6.1.1. Monolithic Applications

6.1.2. Microservice Applications

6.1.3. Integration tests

6.1.4. Contract tests

6.1.5. Consumer-driven contracts

6.2. Tools

6.2.1. Pact

6.2.2. Pact-JVM

6.2.3. Arquillian Algeron

6.3. Build Script Modifications

6.3.1. Pact-JVM

6.3.2. Arquillian Algeron

6.4. Writing Integration Tests for Gamer application

6.4.1. Consumer Side in Comments Service

6.4.2. Provider Side in Comments Service

6.5. Reader Exercise

6.6. Summary

7. End-to-End Testing

7.1. End-to-End Tests in the overall testing picture

7.2. End-to-End Testing Techniques

7.2.1. Vertical Tests

7.2.2. Horizontal Tests

7.3. Introduction to the Tools

7.3.1. Arquillian Cube

7.3.2. Arquillian Drone

7.3.3. Arquillian Graphene 2

7.3.4. JMeter

7.3.5. Cukes in Space

7.4. Example End-to-End Test

7.4.1. Build the Microservices

7.4.2. Add the Build Dependencies and Configuration

7.4.3. Add @Deployment, @TargetsContainer to the Test

7.4.4. Coping With a Mixed Environment Using @BeforeClass

7.4.5. Operate on the Deployments with @OperateOnDeployment

7.4.6. Introducing @Drone, @Page Objects, @Location and the WebDriver

7.4.7. Running the Test

7.5. Reader Exercise

7.6. Summary

8. Docker and Testing

8.1. Tools

8.1.1. Docker

8.1.2. Docker Compose

8.1.3. Arquillian Cube

8.2. Build Script Modifications

8.2.1. Arquillian Cube Docker

8.2.2. Arquillian Cube Docker JUnit Rule

8.2.3. Arquillian Cube Kubernetes

8.2.4. Arquillian Cube OpenShift

8.3. Testing Dockerfile for Video Service

8.4. Reader Exercise

8.5. Summary

9. Service Virtualization

9.1. What is Service Virtualization?

9.1.1. Why Service Virtualization?

9.1.2. When Service Virtualization?

9.2. Tools

9.2.1. Hoverfly

9.3. Build Script Modifications

9.3.1. Hoverfly Java

9.4. Using Service Virtualization for Gamer application

9.5. Summary

10. Continuous Delivery in Microservices

10.1. What is Continuous Delivery ?

10.1.1. Microservice Architecture

10.2. Orchestrating Continuous Delivery

10.2.1. Jenkins

10.2.2. Jenkins Pipeline

10.2.3. Deploying with Certainty

10.3. Tools

10.3.1. Jenkins

10.3.2. Example

10.4. Summary

Appendixes

Appendix A: Arquillian

About the book

Testing Java Microservices teaches you how to write tests for microservices in Java. You'll learn test strategies that solve the most common issues you are likely to encounter. This practical hands-on guide begins with introducing you to microservices and providing you with a simple, carefully-designed application developed using microservices principles and following some of the most common technologies such as Java EE, Spring Boot, WildFly Swarm, and Docker. You'll move on to write tests for microservices architecture, starting with simple but useful unit tests, all the way to end-to-end tests. The book shows you how to write tests like unit, component, integration, container, contract, chaos, and more. Along the way, you'll also learn about some technologies like the Arquillian ecosystem, Wiremock, Mockito, AssertJ, Pact or Gatling. Finally, you'll see how everything fits together into the Continuous Delivery pipeline.

What's inside

  • Test automation
  • Writing Persistence tests
  • Continuous Delivery
  • Creating deployable archives with ShrinkWrap
  • Testing with Docker

About the reader

Readers should be comfortable programming in Java. Experience with testing tools like jUnit is helpful but not required. Some experience in Java EE, Spring. and Docker is also helpful.

About the author

Alex Soto Bueno is a software engineer and is passionate about Java development and the open source software model. He leads the NoSQLUnit project and is a team member and evangelist of Arquillian. He has spread the word of testing at several conferences including Devoxx or GeeCon.

Jason Porter works at Red Hat and has been involved with Arquillian since the early days. He created the first glassfish adapter and laid groundwork for the website. He also has used it extensively while testing Seam 3 and Apache DeltaSpike.

Andy Gumbrecht is a Senior Software Engineer and lead developer on several successful local government and commercial industry projects. As a senior Java developer he has never lost his love for coding, open source and best practices within the industry and has an attention to detail, performance and infrastructure.


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.
Buy
MEAP combo $44.99 pBook + eBook
MEAP eBook $35.99 pdf + ePub + kindle

FREE domestic shipping on three or more pBooks