Fundamentals of TDD

You've heard about testing, and even better "Test-Driven Development", but you're still not sure exactly what they are. Well now you'll know!

In this trail, thoughtbot developers Harry Schwartz and Ian C. Anderson cover core principles of writing code with Test-Driven Development. You'll learn about the benefits of testing, the way testing first applies positive design pressure to your code, and how to apply TDD to your own development.

Topics include the red-green-refactor loop, tests as living documentation of your code, why your test code shouldn't necessarily be free of duplication, leveraging your tests to lower risk when refactoring, and strategies for balancing integration and unit tests.

An included exercise offers an opportunity to get your hands dirty with RSpec and improve an existing test suite.


Fundamentals of TDD - Overview

In this course, we're going to cover the core principles of TDD and how you can use it to improve the code you write and maintain. thoughtbot developers Harry Schwartz and Ian C. Anderson will be your guides throughout the course, guiding you toward more productive development through Test-Driven Development.

Sign In with GitHub for Free Access

Red-Green-Refactor by Example

Learn the red-green-refactor loop, the primary principle of TDD. Write tests first, watch them fail, write code incrementally until the tests pass. With passing tests, use the opportunity to refactor.

Sign In with GitHub for Free Access

Telling a Story with Your Tests

A well-written test case tells a clear story, communicating the intent of code. Learn how to write expressive tests and why duplication isn't always a bad thing in your test cases.

TDD Spec Cleanup Exercise

Put your new TDD knowledge into action with this exercise. You'll take an existing spec and whip it into shape, making it clear and purposeful!

Introducing the Unit Converter

Apply the ideas of TDD to a more complicated piece of code. Isolate specific behaviors and build incrementally, using your test failures to guide your next addition to the code.

Refactoring with Test Coverage

With a test suite in place, you can refactor with confidence, knowing that your tests will guard against regression. Learn how to leverage your tests while refactoring an existing piece of code.

Integration vs. Unit Tests

Integration and unit tests both play important roles in your application's test coverage. Learn when to use each type of tests, guidelines for when to mock collaborators in tests, and how integration and feature tests can drive the creation of unit tests.

Going Further with TDD

Resources for further exploration of Test-Driven Development.

Taught by
  • Harry Schwartz

    Harry Schwartz

    Harry's interested in programming language theory, distributed systems, and teaching—he especially likes Ruby, Lisp, and languages with strong type systems. He organizes EmacsBoston, keeps a weird blog, and wanders around outside a lot.

  • Ian C. Anderson

    Ian C. Anderson

    Ian is a web developer who values good naming and bad puns. He is a fan of Ruby for its expressiveness and focus on TDD, and is interested in functional languages like Elixir, Elm, and Haskell. When he's not trying to find the perfect name for a function, he might be playing music or brewing beer at home.