Learning Test-Driven Development

Book description

Your code is a testament to your skills as a developer. No matter what language you use, code should be clean, elegant, and uncluttered. By using test-driven development (TDD), you'll write code that's easy to understand, retains its elegance, and works for months, even years, to come. With this indispensable guide, you'll learn how to use TDD with three different languages: Go, JavaScript, and Python.

Author Saleem Siddiqui shows you how to tackle domain complexity using a unit test-driven approach. TDD partitions requirements into small, implementable features, enabling you to solve problems irrespective of the languages and frameworks you use. With Learning Test-Driven Development at your side, you'll learn how to incorporate TDD into your regular coding practice.

This book helps you:

  • Use TDD's divide-and-conquer approach to tame domain complexity
  • Understand how TDD works across languages, testing frameworks, and domain concepts
  • Learn how TDD enables continuous integration
  • Support refactoring and redesign with TDD
  • Learn how to write a simple and effective unit test harness in JavaScript
  • Set up a continuous integration environment with the unit tests produced during TDD
  • Write clean, uncluttered code using TDD in Go, JavaScript, and Python

Publisher resources

View/Submit Errata

Table of contents

  1. Foreword
  2. Preface
    1. What Is Test-Driven Development?
      1. A Technique
      2. Designing and Structuring Code
      3. A Bias Toward Simplicity
      4. Increased Confidence
    2. Who Is This Book For?
    3. What Are the Prerequisites for Reading This Book?
    4. How to Read This Book
      1. Follow the Book One Language at a Time
      2. Follow the Book in Two Languages First and Then in the Third Language
      3. Follow the Book in All Three Languages Simultaneously
    5. Conventions Used in This Book
      1. Typographical Conventions
      2. Lexical Conventions
    6. Using Code Examples
    7. How to Contact Us
    8. TDD—The Whys
      1. Why Does This Book Use Go, JavaScript, and Python?
      2. Why Not This Other Language?
      3. Why Does This Book Have a “Chapter 0”?
  3. Chapter 0: Introduction and Setup
    1. Setting Up Your Development Environment
      1. Common Setup
      2. Go
      3. JavaScript
      4. Python
    2. Where We Are
  4. I. Getting Started
  5. 1. The Money Problem
    1. Red-Green-Refactor: The Building Blocks of TDD
    2. What’s the Problem?
    3. Our First Failing Test
      1. Go
      2. JavaScript
      3. Python
    4. Going for Green
      1. Go
      2. JavaScript
      3. Python
    5. Cleaning Up
      1. Go
      2. JavaScript
      3. Python
    6. Committing Our Changes
    7. Where We Are
      1. Go
      2. JavaScript
      3. Python
  6. 2. Multicurrency Money
    1. Enter the Euro
      1. Go
      2. JavaScript
      3. Python
    2. Keeping Code DRY
      1. Go
      2. JavaScript
      3. Python
    3. Didn’t We Just Say “Don’t Repeat Yourself”?!
    4. Divide and Conquer
      1. Go
      2. JavaScript
      3. Python
    5. Cleaning Up
      1. Go
      2. JavaScript
      3. Python
    6. Committing Our Changes
    7. Where We Are
  7. 3. Portfolio
    1. Designing Our Next Test
      1. Go
      2. JavaScript
      3. Python
    2. Committing Our Changes
    3. Where We Are
  8. II. Modularization
  9. 4. Separation of Concerns
    1. Test and Production Code
      1. Unidirectional Dependency
      2. Dependency Injection
      3. Packaging and Deployment
    2. Modularization
    3. Removing Redundancy
    4. Where We Are
  10. 5. Packages and Modules in Go
    1. Separating Our Code into Packages
    2. Go Modules
    3. Creating a Package
    4. Encapsulation
    5. Removing Redundancy in Tests
    6. Committing Our Changes
    7. Where We Are
  11. 6. Modules in JavaScript
    1. Separating Our Code into Modules
    2. A Segue into JavaScript Modules
      1. CommonJS
      2. Asynchronous Module Definition (AMD)
      3. Universal Module Definition (UMD)
      4. ESModules
    3. Improving Our Tests
      1. Removing Redundancy in Tests
      2. Adding a Test Class and Test Methods
      3. Discovering and Running Tests Automatically
      4. Produce Output When Tests Run Successfully
      5. Run All Tests Even When an Earlier Test Assertion Fails
    4. Committing Our Changes
    5. Where We Are
  12. 7. Modules in Python
    1. Separating Our Code into Modules
    2. Removing Redundancy in Tests
    3. Committing Our Changes
    4. Where We Are
  13. III. Features and Redesign
  14. 8. Evaluating a Portfolio
    1. Mixing Money
      1. Go
      2. JavaScript
      3. Python
    2. Committing Our Changes
    3. Where We Are
  15. 9. Currencies, Currencies, Everywhere
    1. Making a Hash(map) of Things
      1. Go
      2. JavaScript
      3. Python
    2. Committing Our Changes
    3. Where We Are
  16. 10. Error Handling
    1. Error Wish List
      1. Go
      2. JavaScript
      3. Python
    2. Committing Our Changes
    3. Where We Are
  17. 11. Banking on Redesign
    1. Dependency Injection
    2. Putting It All Together
      1. Go
      2. JavaScript
      3. Python
    3. Committing Our Changes
    4. Where We Are
  18. IV. Finishing Up
  19. 12. Test Order
    1. Changing Exchange Rates
      1. Go
      2. JavaScript
      3. Python
    2. Committing Our Changes
    3. Where We Are
  20. 13. Continuous Integration
    1. Core Concepts
      1. Version Control
      2. Build Server and Agent
      3. Artifact Repository
      4. Deployment Environment
    2. Putting It All Together
      1. Create Your GitHub Account
      2. Verify Your GitHub Account
      3. Push Code Repository to GitHub
      4. Prepare for CI Build Scripts
      5. Go
      6. JavaScript
      7. Python
    3. Committing Our Changes
    4. Where We Are
  21. 14. Retrospective
    1. Profile
      1. Cyclomatic Complexity
      2. Coupling
      3. Succinctness
    2. Purpose
      1. Cohesion
      2. Completeness
    3. Process
    4. Putting It All Together
      1. Go
      2. JavaScript
      3. Python
    5. Isn’t TDD Dead?
    6. Where We Are
  22. A. Development Environment Setup
    1. Online REPLs
      1. Repl.it
      2. LeetCode
      3. CoderPad
      4. The Go Playground
      5. The Comprehensive List of Online REPLs
    2. Integrated Development Environments (IDEs)
      1. Visual Studio Code
      2. IntelliJ IDEA
      3. Eclipse
    3. Installing Language Tools
      1. Go
      2. JavaScript / ES6
      3. Python
  23. B. A Brief History of the Three Languages
    1. Go
    2. JavaScript
      1. The assert Module
      2. The Module Mechanism
    3. Python
  24. C. Acknowledgments
  25. Index

Product information

  • Title: Learning Test-Driven Development
  • Author(s): Saleem Siddiqui
  • Release date: October 2021
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9781098106478