Learn Testing

Test-driven development, or TDD, is the practice of writing your tests firsts, then using those tests to guide you as you write your actual production code. This may sound crazy, but it turns out that it makes writing code much easier. It provides a clear workflow and next steps while you're building and has the added benefit of producing a test suite you can have confidence in. With these courses and videos we'll teach you everything you need to know to get started with TDD.

With a solid test suite, you'll have more confidence every time you push a change up to production. You'll also be able to refactor with confidence, changing the structure of your application and remaining certain that all the important functionality still works. Even better, since TDD forces you to interact with your code as you test it, it provides great feedback as to when you might want to clean up some of the rough edges.

The aim of test driven development is to produce code that is as simple as possible in order to meet all required criteria, and many of our training graduates (and others who have learned these methods) find that it’s also a great way to produce very robust code. By its very nature the finished product has been tested rigorously by the time it’s ready to roll out.

We think that test driven development is a great skill for aspiring coders to have, and our tutorials are the ideal place to start. We begin by introducing the concepts and by the time you’ve finished the training, you should have a full toolbox ready to deploy TDD in the real world.

Trails

Testing

Test Doubles

Learn to use stubs, mocks, spies, and fakes with RSpec.

?

Learn to use stubs, mocks, spies, and fakes with RSpec.

6 hours
Next Up

Simple Stubs

Use rspec-mocks to stub out an object in a test.

Unstarted

Stubs with Constraints

Learn to set constraints on stubbed methods using RSpec.

Unstarted

Setting Expectations with Mocks

Learn to unit test methods with side effects and mutation using mocks.

Unstarted

Verifying Expectations with Spies

Learn how to keep your unit tests tidy with an alternative to mocks: spies.

Unstarted

Testing Flexible Interactions with Fakes

Learn how to test complex or flexible interactions by using fakes.

Unstarted

Verifying Mailers with Test Doubles

Now that you've learned how to use stubs, mocks, spies, and fakes, it's time to pull it all together.

6 steps remaining
Visit trail
Testing

Rails Testing Exercises

So you want to get started with Ruby testing. All the cool kids are doing it. Seriously though, testing is fundamental. In this course of tutorials you’ll learn methods for improving code quality and minimizing time required to add new features to software by ensuring that each facet of the program works as expected.

?

So you want to get started with Ruby testing. All the cool kids are doing it. Seriously though, testing is fundamental. In this course of tutorials you’ll learn methods for improving code quality and minimizing time required to add new features to software by ensuring that each facet of the program works as expected.

5 hours
Next Up

Passing Your First Test

In order to get your feet wet with testing, let's write a test for a simple Ruby class.

Unstarted

Testing ActiveRecord

In this exercise, you'll write an RSpec model test to verify a simple validation.

Unstarted

Write an Integration Test

In this example, we'll be using Capybara to write an integration test.

Unstarted

Write a controller spec

In this example, you'll write a unit test to make sure the create action for PeopleController works as expected based on the return value of save.

Unstarted

Write A Feature With Tests

Time to put it all together! In this exercise, you'll add enhance a small Rails applications by adding the ability edit existing people. You'll implement the necessary actions and views in the Rails application, writing tests as you go.

5 steps remaining
Visit trail
Ruby on Rails Testing

Test-Driven Rails

Learn Test-Driven Rails Development using RSpec and Capybara in this series of tutorials. As part of the course, you can follow along with Josh as he lets his test drive through each of the steps needed to build out an application.

?

Learn Test-Driven Rails Development using RSpec and Capybara in this series of tutorials. As part of the course, you can follow along with Josh as he lets his test drive through each of the steps needed to build out an application.

2 hours 18 minutes
Next Up

Introduction

The Ruby and Rails communities have begun to embrace test-driven design, and for many employers, it's a skill expected of developers. At thoughtbot, we consider it a core competency and drive all development through tests. For developers new to testing, however, the most common question asked is, "Why test?" Josh discusses the goals of testing, forms of testing, and the tools we commonly use when testing Rails applications.

Unstarted

Setting Up the App and Initial Test

Time to write our first test! In this video, Josh discusses how to lay the foundation of a test suite within a Rails application, outlines the structure of an acceptance test, and writes an initial test ensuring we can interact with the application itself.

Unstarted

Creating the First Todo

With an understanding of basic browser interactions, we're now equipped to dig deeper into the Todo application. We'll discuss new test assertions and how to interact with forms by creating a todo.

Unstarted

Signing In and Todo Ownership

A list of todos is arguably valuable only when the list is owned by one person (or a group of people), but not everyone in the world. In this video, Josh introduces a simple User model and ensures that the todos created are assigned to the person who's "signed in."

Unstarted

Refactor to User Model

We've gone over "Red, Green, Refactor", but haven't performed a larger refactor in the todo codebase. In this video, Josh refactors the controllers to isolate interaction of `session` and introduces a `User` class which mimics a basic authentication library.

Unstarted

Completing a Todo

Managing a list of tasks to accomplish is great, but you know what's even cooler? Being able to mark things as done. In this video, Josh drives tracking completion of todos through acceptance and unit tests, and covers the intricacies of RESTful actions within the todo application.

Unstarted

Refactoring Todo Completions

Tests are code too, and as such, they can be refactored during the "Refactor" step of "Red, Green, Refactor." In this video, Josh covers how to extract common interactions and assertions in the test suite (having introduced similar paths through todo creation, todo ownership, and todo completion).

Unstarted

Marking Todos Incomplete

What happens when you incorrectly mark a todo complete? You mark it incomplete, of course! In this video, Josh introduces functionality to mark completed todos as incomplete, and refactors the controller to leverage a similar interface to marking a todo as complete.

8 steps remaining
Visit trail
Testing

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.

?

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.

2 hours 15 minutes
Next Up

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.

Unstarted

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.

Unstarted

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.

Unstarted

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!

Unstarted

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.

Unstarted

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.

Unstarted

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.

Unstarted

Going Further with TDD

Resources for further exploration of Test-Driven Development.

8 steps remaining
Visit trail

The Weekly Iteration

Hosted by

Ben Orenstein and Chris Toomey

Ben Orenstein
Chris Toomey

In this screencast, Ben and Chris go back to basics and tackle the first exercise in the Rails Fundamentals trail, "Route, Controller, Action". They create a route, controller, and action using TDD to tell them what to write next.

Hosted by

Ben Orenstein and Joe Ferris

Ben Orenstein
Joe Ferris

This episode covers one method of dividing a test into four distinct phases and the benefits of doing so. xUnit Patterns Wiki xUnit Test Patterns book

Hosted by

Chris Toomey and Joshua Clayton

Chris Toomey
Joshua Clayton

On this week's episode, Chris is again joined by Josh Clayton, Boston Development Director and TDD master, this time to discuss the power of page objects for cleaning up feature specs.

Hosted by

Ben Orenstein and Joe Ferris

Ben Orenstein
Joe Ferris

Joe and Ben discuss the reasons for testing, and how integration and unit testing each serve different reasons. Dive into the benefits of drawbacks of testing at each point in the isolation/integration spectrum by looking through examples.

Hosted by

Joe Ferris and Gabe Berke-Williams

Joe Ferris
Gabe Berke-Williams

Joe and Gabe review the four types of test doubles: stubs, mocks, spies and fakes. Learn what the key differences are between each type, as well as when you'd want to consider using them. See examples written using rspec-mocks, as well as an...

Hosted by

Chris Toomey and Joe Ferris

Chris Toomey
Joe Ferris

Tests are code too, and they deserve the same love and careful refactoring you'd show to your production code. In fact, there are a number of antipatterns and pitfalls unique to test code that can trip you up. Tune in to learn all the dos and...

Hosted by

Chris Toomey and Ben Orenstein

Chris Toomey
Ben Orenstein

Recently, we ran a group-coding app-building contest for Upcase subscribers. In this video, Ben and Chris review each of the submissions, both highlighting great aspects and suggesting some areas for improvement. Live code review at its finest!

Hosted by

Chris Toomey and Derek Prior

Chris Toomey
Derek Prior

On this week's episode, Chris is joined by Derek Prior to discuss Rspec's Bisect, a tool to track down order-dependence in your test suite and banish pesky intermittent test failures.

Hosted by

Joel Quenneville and Chris Toomey

Joel Quenneville
Chris Toomey

If your application uses third-party APIs, it can be complicated to write good, flexible tests that don't depend on the service being present (or don't touch production data). In this Weekly Iteration, Joël Quenneville and Chris Toomey examine...

Hosted by

Paul Smith and Chris Toomey

Paul Smith
Chris Toomey

Elixir & Phoenix, so hot right now! On this week’s episode we’ll take a look at some of the great features of both Elixir and Phoenix through the lens of Bamboo, a library for sending emails in Phoenix apps, recently released by thoughtbot...

Hosted by

Joel Quenneville and Ben Orenstein

Joel Quenneville
Ben Orenstein

Joël Quenneville presents the why, what, and how of testing in isolation!