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.
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.2. YoutubeLink 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 Tests
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.
- MEAP combo $44.99 pBook + eBook
- MEAP eBook $35.99 pdf + ePub + kindle
FREE domestic shipping on three or more pBooks