Test-Driven Development: Extensive Tutorial
Test-Driven Development: Extensive Tutorial
About the Book
This ebook is an attempt to create open-source extensive tutorial on Test-Driven Development.
Source code is at https://github.com/grzesiek-galezowski/tdd-ebook
This book is and always will be free.
About the Contributors
Cover Designer
Table of Contents
-
Front Matter
- Dedications
- Thanks!
-
About code examples
- Notes for C# users
- Notes for Java users
-
Part 1: Just the basics
-
Motivation – the first step to learning TDD
- What TDD feels like
- Let’s get it started!
-
The essential tools
- Test framework
- Mocking framework
- Anonymous values generator
- Summary
-
It’s not (only) a test
- When a test becomes something more
- Taking it to the software development land
- A Specification rather than a test suite
- The differences between executable and “traditional” specifications
-
Statement-first programming
- What’s the point of writing a specification after the fact?
- “Test-First” means seeing a failure
- “Test-After” often ends up as “Test-Never”
- “Test-After” often leads to design rework
- Summary
-
Practicing what we have already learned
- Let me tell you a story
- Act 1: The Car
- Act 2: The Customer’s Site
- Act 3: Test-Driven Development
- Epilogue
- Sorting out the bits
-
How to start?
- Start with a good name
- Start by filling the GIVEN-WHEN-THEN structure with the obvious
- Start from the end
- Start by invoking a method if you have one
- Summary
-
How is TDD about analysis and what does “GIVEN-WHEN-THEN” mean?
- Is there a commonality between analysis and TDD?
- Gherkin
- TODO list… again!
-
What is the scope of a unit-level Statement in TDD?
- Scope and level
- On what level do we specify our software?
- What should be the functional scope of a single Statement?
- Failing to adhere to the three rules
- How many assertions do I need?
- Summary
-
Developing a TDD style and Constrained Non-Determinism
- A style?
- Principle: Tests As Specification
- First technique: Anonymous Input
- Second technique: Derived Values
- Third technique: Distinct Generated Values
- Fourth technique: Constant Specification
- Summary of the example
- Constrained non-determinism
- Summary
-
Specifying functional boundaries and conditions
- Sometimes, an anonymous value is not enough
- Exceptions to the rule
- Rules valid within boundaries
- Combination of boundaries – ranges
- Summary
-
Driving the implementation from Specification
- Type the obvious implementation
- Fake it (‘til you make it)
- Triangulate
- Summary
-
Motivation – the first step to learning TDD
-
Part 2: Object-Oriented World
-
On Object Composability
- Another task for Johnny and Benjamin
- A Quick Retrospective
-
Telling, not asking
- Contractors
- A Quick Retrospective
-
The need for mock objects
- Composability… again!
-
Why do we need composability?
- Pre-object-oriented approaches
- Object-oriented programming to the rescue!
- The power of composition
- Summary – are you still with me?
-
Web, messages and protocols
- So, again, what does it mean to compose objects?
- Alarms, again!
- Summary
-
Composing a web of objects
- Three important questions
- A preview of all three answers
- When are objects composed?
-
How does a sender obtain a reference to a recipient (i.e. how connections are made)?
- Receive as a constructor parameter
- Receive inside a message (i.e. as a method parameter)
- Receive in response to a message (i.e. as a method return value)
- Receive as a registered observer
-
Where are objects composed?
- Composition Root
- Factories
- Summary
-
Interfaces
- Classes vs interfaces
- Events/callbacks vs interfaces – few words on roles
- Small interfaces
-
Protocols
- Protocols exist
- Protocol stability
- Craft messages to reflect the sender’s intention
- Model interactions after the problem domain
- Message recipients should be told what to do, instead of being asked for information
- Most of the getters should be removed, return values should be avoided
- Protocols should be small and abstract
- Summary
-
Classes
- Single Responsibility Principle
- Static recipients
- Summary
-
Object Composition as a Language
- More readable composition root
- Refactoring for readability
- Composition as a language
- The significance of a higher-level language
- Some advice
- Summary
-
Value Objects
- What is a value object?
- Example: money and names
-
Value object anatomy
- Class signature
- Hidden data
- Hidden constructor
- String conversion methods
- Equality members
- The return of investment
- Summary
-
Aspects of value objects design
- Immutability
- Handling of variability
- Special values
- Value types and Tell Don’t Ask
- Summary
-
On Object Composability
-
Part 3: TDD in Object-Oriented World
-
Mock Objects as a testing tool
- A backing example
- Interfaces
- Protocols
- Roles
- Behaviors
- Filling in the roles
- Using a mock channel
- Mocks as yet another context
- Summary
-
Test-first using mock objects
- How to start? – with mock objects
- Responsibility and Responsibility
- Channel and DataDispatch one more time
- The first behavior
- Second behavior – specifying an error
- Summary
-
Test-driving at the input boundary
- Fixing the ticket office
- Initial objects
- Bootstrap
- Writing the first Statement
- Summary
-
Test-driving at the input boundary – a retrospective
- Outside-in development
- Workflow specification
- Data Transfer Objects and TDD
-
Using a
ReservationInProgress
- Interface discovery and the sources of abstractions
- Do I need all of this to do TDD?
- What’s next?
- Test-driving object creation
-
Test-driving object creation – a retrospective
- Limits of creation specification
- Why specify object creation?
- What do we specify in the creational Statements?
- Value object creation
- Summary
-
Test-driving application logic
- Summary
-
Test-driving value objects
- Initial value object
- Value semantics
- Case-insensitive comparison
- Input validation
- Summary
-
Reaching the web of objects boundaries
- What time is it?
- Timers
- Threads
- Others
- THIS IS ALL I HAVE FOR NOW. WHAT FOLLOWS IS RAW, UNORDERED MATERIAL THAT’S NOT YET READY TO BE CONSUMED AS PART OF THIS TUTORIAL
-
Mock objects as a design tool
- Responsibility-Driven Design
-
What not to mock?
- Internals
-
Guidance of test smells
- Long Statements
- Lots of stubbing
- Specifying private members
-
Revisiting topics from chapter 1
- Constrained non-determinism in OO world
- Behavioral boundaries
- Triangulation
-
Maintainable mock-based Statements
- Setup and teardown
- Refactoring mock code
-
Mock Objects as a testing tool
-
Part 4: Application architecture
- On stable/architectural boundaries
-
Ports and adapters
- Physical separation of layers
-
What goes into application?
- Application and other layers
-
What goes into ports?
- Data transfer objects
- Ports are not a layer
-
Part 5: TDD on application architecture level
-
Designing automation layer
- Adapting screenplay pattern
- Driver
- Actors
- Data builders
-
Further Reading
- Motivation – the first step to learning TDD
- The Essential Tools
- Value Objects
-
Designing automation layer
- Notes
The Leanpub 60-day 100% Happiness Guarantee
Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.
See full terms
Do Well. Do Good.
Authors have earned$11,817,855writing, publishing and selling on Leanpub, earning 80% royalties while saving up to 25 million pounds of CO2 and up to 46,000 trees.
Learn more about writing on Leanpub
Free Updates. DRM Free.
If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).
Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.
Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.
Learn more about Leanpub's ebook formats and where to read them
Top Books
Stratospheric
Tom Hombergs, Björn Wilmsmann, and Philip RiecksFrom Zero to Production with Spring Boot and AWS. All you need to know to get a Spring Boot application into production with AWS. No previous AWS knowledge required.
Go to stratospheric.dev for a tour of the contents.
C++20 - The Complete Guide
Nicolai M. JosuttisAll new language and library features of C++20 (for those who know previous C++ versions).
The book presents all new language and library features of C++20. Learn how this impacts day-to-day programming, to benefit in practice, to combine new features, and to avoid all new traps.
Buy early, pay less, free updates.
Other books:
OpenIntro Statistics
David Diez, Christopher Barr, Mine Cetinkaya-Rundel, and OpenIntroA complete foundation for Statistics, also serving as a foundation for Data Science.
Leanpub revenue supports OpenIntro (US-based nonprofit) so we can provide free desk copies to teachers interested in using OpenIntro Statistics in the classroom and expand the project to support free textbooks in other subjects.
More resources: openintro.org.
node-opcua by example
Etienne RossignonGet the best out of node-opcua through a set of documented examples by the author himself that will allow you to create stunning OPCUA Servers or Clients.
Advanced Web Application Architecture
Matthias NobackThe missing manual for making your web applications future-proof
Jetpack Compose internals
Jorge CastilloJetpack Compose is the future of Android UI. Master how it works internally and become a more efficient developer with it. You'll also find it valuable if you are not an Android dev. This book provides all the details to understand how the Compose compiler & runtime work, and how to create a client library using them.
Ansible for DevOps
Jeff GeerlingAnsible is a simple, but powerful, server and configuration management tool. Learn to use Ansible effectively, whether you manage one server—or thousands.
R Programming for Data Science
Roger D. PengThis book brings the fundamentals of R programming to you, using the same material developed as part of the industry-leading Johns Hopkins Data Science Specialization. The skills taught in this book will lay the foundation for you to begin your journey learning data science. Printed copies of this book are available through Lulu.
Thinking with Types
Sandy MaguireThis book aims to be the comprehensive manual for type-level programming. It's about getting you from here to there---from a competent Haskell programmer to one who convinces the compiler to do their work for them.
Maîtriser Apache JMeter
Philippe Mouawad, Bruno Demion (Milamber), and Antonio Gomes RodriguesToute la puissance d'Apache JMeter expliquée par ses commiteurs et utilisateurs experts. De l'intégration continue en passant par le Cloud, vous découvrirez comment intégrer JMeter à vos processus "Agile" et Devops.
If you're looking for the newer english version of this book, go to Master JMeter : From load testing to DevOps
Top Bundles
- #1
CCIE Service Provider Ultimate Study Bundle
2 Books
Piotr Jablonski, Lukasz Bromirski, and Nick Russo have joined forces to deliver the only CCIE Service Provider training resource you'll ever need. This bundle contains a detailed and challenging collection of workbook labs, plus an extensively detailed technical reference guide. All of us have earned the CCIE Service Provider certification... - #3
Software Architecture
2 Books
"Software Architecture for Developers" is a practical and pragmatic guide to modern, lightweight software architecture, specifically aimed at developers. You'll learn:The essence of software architecture.Why the software architecture role should include coding, coaching and collaboration.The things that you really need to think about before... - #4
Pattern-Oriented Memory Forensics and Malware Detection
2 Books
This training bundle for security engineers and researchers, malware and memory forensics analysts includes two accelerated training courses for Windows memory dump analysis using WinDbg. It is also useful for technical support and escalation engineers who analyze memory dumps from complex software environments and need to check for possible... - #5
Practical FP in Scala + Functional event-driven architecture
2 Books
Practical FP in Scala (A hands-on approach) & Functional event-driven architecture, aka FEDA, (Powered by Scala 3), together as a bundle! The content of PFP in Scala is a requirement to understand FEDA so why not take advantage of this bundle!? - #10
Cloud Architect: Transform Technology and Organization
2 Books
Architects don't just recite product names and features. They understand the options, decisions, and trade-offs behind them. They earn credibility and maintain authenticity by connecting the penthouse with the engine room. Get two essential books that redefine the role of the software and IT architect at one low price:37 Things One Architect...