quick-links

TDD Introduction

Test-Driven Development

Test-driven development is the act of first deciding what you want your program to do (the specifications), formulating a failing test, then writing the code to make that test pass. It is most often associated with automated testing. Although you could apply the principals to manual testing as well.

Let’s look at a simple example:

Building a wooden table. Traditionally, we would make a table, then once the table is made, test it to make sure it does, well, what a table should do. TDD, on the other hand, would have us first define what the table should do. Then when it isn’t doing those things, add the minimum amount of “table” to make each unit work.

Here an example of TDD for building a wooden table:

I expect the table to be four feet in diameter.

The test fails because I have no table.

I cut a circular piece of wood four feet in diameter.

The test passes.

________________________________________________________________

I expect the table to be three feet high.

The test fails because it is sitting on the ground.

I add one leg in the middle of the table.

The test passes.

________________________________________________________________

I expect the table to hold a 20-pound object.

The test fails because when I place the object on the edge, it makes the table fall over since there is only one leg in the middle.

I move the one leg to the outer edge of the table and add two more legs to create a tripod structure.

The test passes.

This would continue on and on until the table is complete.

Test my Bootcamp using JSBin

Here is a list of JSBin exercises that you can complete online to practice you MochaJS & Unit Testing skills.

To be completed by that people is working remotely and that don’t have access to a Laptop. But they are good practice even for all.

JSBin URL Bootcamp function name
greet greet
isFromBellville isFromBellville
regCheck regCheck
countRegNumber countRegNumber
isWeekDay isWeekDay
transportFee transportFee

Screencasts to watch

Let us know at mentors@projectcodex.co is you want the videos via WhatsApp.