Book description
Drive development with automated tests and gain the confidence you need to write high-quality software
Key Features
- Get up and running with common design patterns and TDD best practices
- Learn to apply the rhythms of TDD – arrange, act, assert and red, green, refactor
- Understand the challenges of implementing TDD in the Java ecosystem and build a plan
Book Description
Test-driven development enables developers to craft well-designed code and prevent defects. It's a simple yet powerful tool that helps you focus on your code design, while automatically checking that your code works correctly. Mastering TDD will enable you to effectively utilize design patterns and become a proficient software architect.
The book begins by explaining the basics of good code and bad code, bursting common myths, and why Test-driven development is crucial. You'll then gradually move toward building a sample application using TDD, where you'll apply the two key rhythms -- red, green, refactor and arrange, act, assert. Next, you'll learn how to bring external systems such as databases under control by using dependency inversion and test doubles. As you advance, you'll delve into advanced design techniques such as SOLID patterns, refactoring, and hexagonal architecture. You'll also balance your use of fast, repeatable unit tests against integration tests using the test pyramid as a guide. The concluding chapters will show you how to implement TDD in real-world use cases and scenarios and develop a modern REST microservice backed by a Postgres database in Java 17.
By the end of this book, you'll be thinking differently about how you design code for simplicity and how correctness can be baked in as you go.
What you will learn
- Discover how to write effective test cases in Java
- Explore how TDD can be incorporated into crafting software
- Find out how to write reusable and robust code in Java
- Uncover common myths about TDD and understand its effectiveness
- Understand the accurate rhythm of implementing TDD
- Get to grips with the process of refactoring and see how it affects the TDD process
Who this book is for
This book is for expert Java developers and software architects crafting high-quality software in Java. Test-Driven Development with Java can be picked up by anyone with a strong working experience in Java who is planning to use Test-driven development for their upcoming projects.
Table of contents
- Test-Driven Development with Java
- Contributors
- About the author
- About the reviewers
- Preface
- Part 1: How We Got to TDD
- Chapter 1: Building the Case for TDD
- Chapter 2: Using TDD to Create Good Code
- Chapter 3: Dispelling Common Myths about TDD
- Part 2: TDD Techniques
- Chapter 4: Building an Application Using TDD
- Chapter 5: Writing Our First Test
- Chapter 6: Following the Rhythms of TDD
- Chapter 7: Driving Design – TDD and SOLID
-
Chapter 8: Test Doubles – Stubs and Mocks
- Technical requirements
- The problems collaborators present for testing
- The purpose of test doubles
- Using stubs for pre-canned results
- Using mocks to verify interactions
- Understanding when test doubles are appropriate
- Working with Mockito – a popular mocking library
- Driving error handling code with tests
- Testing an error condition in Wordz
- Summary
- Questions and answers
- Further reading
-
Chapter 9: Hexagonal Architecture –Decoupling External Systems
- Technical requirements
- Why external systems are difficult
- Dependency inversion to the rescue
- Abstracting out the external system
- Writing the domain code
- Substituting test doubles for external systems
- Unit testing bigger units
- Wordz – abstracting the database
- Summary
- Questions and answers
- Further reading
- Chapter 10: FIRST Tests and the Test Pyramid
-
Chapter 11: Exploring TDD with Quality Assurance
- TDD – its place in the bigger quality picture
- Manual exploratory – discovering the unexpected
- Code review and ensemble programming
- User interface and user experience testing
- Security testing and operations monitoring
- Incorporating manual elements into CI/CD workflows
- Summary
- Questions and answers
- Further reading
- Chapter 12: Test First, Test Later, Test Never
- Part 3: Real-World TDD
- Chapter 13: Driving the Domain Layer
- Chapter 14: Driving the Database Layer
- Chapter 15: Driving the Web Layer
- Index
- Other Books You May Enjoy
Product information
- Title: Test-Driven Development with Java
- Author(s):
- Release date: January 2023
- Publisher(s): Packt Publishing
- ISBN: 9781803236230
You might also like
book
Java to Kotlin
It takes a week to travel the 8,000 miles overland from Java to Kotlin. If you're …
video
Java SE 11 Developer (1Z0-819)
18+ Hours of Video Instruction Description An intensive study resource designed to guide you in best …
book
Hands-On Software Architecture with Java
Build robust and scalable Java applications by learning how to implement every aspect of software architecture …
book
Modern Java in Action
Manning's bestselling Java 8 book has been revised for Java 9 and 10! In Modern Java …