No description, website, or topics provided.
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


Intro to TDD

Why is this important?

This workshop is important because:

  • Automated testing can save tons of time and money!
  • Test Driven Development guaruntees excellent test coverage
  • TDD is a great way for Jr. Devs to contribute a lot of code!

What are the objectives?

After this workshop, developers will be able to:

  • Explain what TDD testing is and why people use it
  • Write code to pass tests

What is TDD

Test driven development is when tests are written before the code it tests.

It basically works like this:

  1. A senior or lead dev writes a test suite for a set of User Stories.
  2. These get handed off to a more junior dev, who write the simplest possible code to get the tests passing.
  3. They then go back and refactor the code so it is more DRY, readable, maintainable, etc.

"Knowing" TDD means different things.

  1. It means if you are given a set of tests, you are able to use those tests and write your code to pass the tests
  2. It means you are able to write the tests before the code.

We are going to give you a basic idea of how the latter works, but as I mentioned this is something that a more senior dev would normally do. It is hard to picture what the code to pass the test should look like in order to write a test for code that doesn't yet exist!

Pros and Cons of TDD


  1. Guarunteed test coverage
  2. Good way for Junior Devs to get a lot done
  3. It's fun to write code to pass tests!


  1. You need a solid, experienced dev to write the tests! Which is expensive!
  2. It takes a significant up front investment of time and money.
  3. If User Stories change, you have to change your tests and the code!

How to get the most out of TDD

There is a lot of discussion on this topic, and many smart people with legitimate opinions, and they don't all agree. I will share two popular patterns for TDD.

Pattern 1:

I have read of one pattern for TDD that I like the best, and seems to be pretty popular, and works great if you don't have a highly experienced Test Developer:

  1. Write a E2E test for the feature you want (i.e. User Sign Up)
  2. Write the code that passes that test.
  3. Refactor that code
  4. When that is passing, if there are any stand alone functions that would be a good candidate for a Unit test, write that after.
  5. If you want, write an integration test.

This is a great deal easier than writing Unit or Integration tests first, because you don't have to make too many low level desicions about design while writing your tests.

Pattern 2:

This an work well if you do have an experienced tester. It is more difficult, but can result in more comprehensive test coverage:

  1. Write E2E and integration tests for a feature
  2. Write the code that passes those tests
  3. Refactor
  4. Add Unit tests where appropriate.

There are several more ways of doing things, as long as some tests are written before production code, it's TDD!

Doing TDD

We aren't going to go through the process of writing tests, we did that in our E2E and Unit testing lessons! But, if you want practice coding from tests, check out this great lab to create a Express Todo app with TDD! The tests are written in Mocha, but you run the tests the same way, using npm run test.

If and when you want to work on writing tests first, I suggest pattern one from above, and doing a practice run on an easy project, like an Express Todo API. Happy coding!