Testing Java Microservices
Alex Soto Bueno, Jason Porter and Andy Gumbrecht
  • MEAP began July 2015
  • Publication in April 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.

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.

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

7. End to End tests

8. Continuous Delivery in Microservices

Appendixes

Appendix A: Code Coverage

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