33,59 €
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.
Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:
Seitenzahl: 480
Veröffentlichungsjahr: 2023
Create higher-quality software by writing tests first with SOLID and hexagonal architecture
Alan Mellor
BIRMINGHAM—MUMBAI
Copyright © 2022 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author(s), nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
Group Product Manager: Gebin George
Publishing Product Manager: Arvind Sharma
Senior Editor: Nisha Cleetus
Technical Editor: Jubit Pincy
Copy Editor: Safis Editing
Project Coordinator: Manisha Singh
Proofreader: Safis Editing
Indexer: Subalakshmi Govindhan
Production Designer: Shankar Kalbhor
Business Development Executive: Kriti Sharma
Marketing Coordinator: Sonakshi Bubbar
First published: January 2023
Production reference: 1231222
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham
B3 2PB, UK.
ISBN 978-1-80323-623-0
www.packt.com
In memory of my mum, Eva Mellor (1928 – 2022). You saw me start this book but not finish it. If I’m perfectly honest, you wouldn’t have enjoyed it as much as your Georgette Heyer novels.
– Alan Mellor
Alan Mellor is an academy lead at BJSS, training the next generation of consulting software engineers, and the author of Java OOP Done Right: Create object oriented code you can be proud of with modern Java. Alan started with a Sinclair ZX81 computer with 1K of RAM and is very happy to have better computers now. Alan’s work includes industrial control in C, web applications for e-commerce, gaming and banking in Java and Go, and document warehousing in C++. His most visible code is part of Nokia Bounce and the RAF Red Arrows flight simulator if you go back far enough.
I want to thank my wife Stephanie without whose support this book would not have been possible. I’m grateful to everyone who has taught me about software engineering, whether in person or via their books. All my love to Jake and Katy. You two are awesome.
Jeff Langr has been building software professionally for over 4 decades. He’s recognized as the author of five books on software development, including Modern C++ Programming with Test–Driven Development: Code Better, Sleep Better, Agile in a Flash (with Tim Ottinger), and Agile in a Flash: Speed-learning Agile Software Development. Jeff is also a co-author of the best-selling book Clean Code. He’s written over a hundred published articles and several hundred blog posts on his site (https://langrsoft.com).
Nikolai Avteniev started his professional career at JPMorgan Chase, participated in the Extreme Programming Pilot, and learned how to apply test-driven development and continuous integration. After graduating from NYU with a degree in computer science, he took the experience of building and running an Agile development team to Real Time Risk Systems as one of the founding engineers. Nikolai later joined New York City AdTech start-up Intent Media and then moved on to building software teams and systems at LinkedIn (https://engineering.linkedin.com/blog/2017/08/getting-to-know-nikolai-avteniev).
Additionally, Nikolai teaches software engineering at the City University of New York. Currently, he works at Stripe, helping grow the GDP of the internet safely.
In Part 1, we look at how we got to TDD in the software industry. What problems are we trying to fix with TDD? What opportunities does it create?
In the following chapters, we will learn about the benefits that TDD brings to businesses and developers. We’ll review the basics of good code to provide something to aim for when we first start writing our tests. Knowing that teams are sometimes hesitant to start using TDD, we will examine six common objections and how to overcome them.
This part has the following chapters:
Chapter 1, Building the Case for TDDChapter 2, Using TDD to Create Good CodeChapter 3, Dispelling Common Myths about TDDWe’ve seen that bad code is bad news: bad for business, bad for users, and bad for developers. Test-driven development (TDD) is a core software engineering practice that helps us keep bad code out of our systems.
The goal of this chapter is to learn the specifics of how TDD helps us to create well-engineered, correct code, and how it helps us to keep it that way. By the end, we will understand the basic principles behind good code and how TDD helps us create it. It is important for us to understand why TDD works in order to motivate us and so that we have a response to give to colleagues about why we recommend that they use it as well.
In this chapter, we’re going to cover the following main topics:
Designing good quality codeRevealing design flawsPreventing logic flawsProtecting against future defectsDocumenting our codeGood quality code