
The idea behind test driven development is that you let the tests ‘drive’ your development process. How does this work? Start by writing a test that fails, then develop the code to make that test pass, then refactor. This cycle is called red, green, refactor.

A diagram to show the red, green, refactor TDD cycle
RED: The red phase is the starting point of the cycle, where you define expectations for the piece of code being tested, and let the test fail. Write tests starting at the lowest level, e.g. when the function is passed an empty array, return an empty array. Why let the test fail? So that you know you have written a good test – a test shouldn’t be able to pass without any logic.
GREEN: Implement the necessary logic to make your test pass – don’t worry about it being the most optimised or efficient at this stage, the goal is to pass the test!
REFACTOR: During the refactor phase, consider how you could optimise your code, without adding any additional functionality.
So, now that you know about the process, what are the benefits of Test-Driven Development?
The foundations are in place before you build the house
With TDD you can dictate exactly what you expect your code to do from the ground up. TDD forces you to think about exactly what you expect from scenario to scenario, which makes you more likely to cover all the bases.
TDD helps you to develop the logic in your code
By starting tests with the simplest functionality first, you can use them to guide your logic as you build up functionality. This helps you to break a problem down into smaller, more manageable pieces, thus aiding the problem solving process.
Very high test-coverage
Test-coverage refers to the percentage of your code that is tested. A high test coverage means that you can trust your code works because you have a large set of tests, and TDD allows for this because you shouldn’t have any code written which doesn’t have the associated tests.
Improved quality of your code
As you are specifically writing code to pass the tests in place, and refactoring at the end of each test; you ensure your code is clean and optimised without any extra pieces of code that you won’t need.
Prevents bugs early on in the development process
As you are adding to the functionality of your code as you go along, you ensure that each stage of the code is working as you progress. Much better than writing a large piece of code, and trying to test it afterwards only to find that it fails!
Easy to add functionality to your code
With a high test coverage, you are simply adding to a very tested piece of code. This is great because you know you can rely on the code you already have, and can write additional tests to add functionality bit by bit.
Your code can be understood easily
One great benefit of testing in general (and using descriptive test statements!), is the readability this provides for others. Developers, testers and non-technical colleagues working on or around the codebase can identify exactly what the piece of code does without any guesswork – great for when you are working on an older codebase and want to navigate around it easily.
Want to try it out for yourself? Get started with some resources below:
Uncle Bob’s Three Rules of TDD
Three Rules of TDD – Youtube Video
Kata – the Only Way To Learn TDD

The Benefits of Test-Driven Development (TDD)
The idea behind test driven development is that you let the tests ‘drive’ your development process. How does this work? Start by writing a test that fails, then develop the code to make that test pass, then refactor. This cycle is called red, green, refactor. A diagram to show the red, green, refactor TDD cycle RED: The…

How to choose which coding language to learn first
Choosing which programming language to learn can be very daunting. There are over 700 languages currently listed by Wiki. Where should you begin? If you take anything away from reading this, it should be one key point; we strongly recommend learning one language in-depth and not two or three casually. What can happen if I choose…

Coding Bootcamp vs. Self Study: Pros & Cons Explained
If you’re starting to code, you’ll have a few different routes to take with your learning process. Everyone is different, so working out what’s the best option for your journey is important. We’ve outlined some pros and cons of bootcamp vs. self-study to help you make a decision. Self Study Pros Cons Coding Bootcamps Pros…

5 Resources to Learn to Code for Absolute Beginners
Whether you’ve played about with your MySpace page back in the early noughties or you don’t know your Ruby from your Python, everyone who codes started somewhere. So we’ve put together some resources that can help you get going. freeCodeCamp This website is great for complete beginners. We encourage everyone who’s interested in our courses…

The Beginner’s Guide to forEach, map and filter in JavaScript
What even are JavaScript Array Methods? Now that you’re getting started with the basics of JavaScript, at some point soon you’ll likely come across three seemingly magical words in many code examples: .forEach(), .map() and .filter(). When you go to loop through (or iterate through) an array, the first thing you think of is probably a for loop. .forEach(), .map() and .filter() are all just other ways…

You CAN Become a Software Engineer Without a Degree. Here’s How
You don’t need to study computer programming at uni to get your foot on the coding career ladder. With the right help, training and support, you could go from absolute beginner to junior engineer in as little as 13 weeks — no qualifications required. Here’s how… For those pursuing a career in software development, the…

Ellie: Mechanical Engineer to Software Developer
It definitely lived up to the hype. I was very focused on finding the ‘right’ job – I really felt they understood what I wanted How did you find your time on the bootcamp? I already had great expectations of the course after hearing about it from a friend, and it definitely lived up to…

Reduce: Five Unusual Uses
…for the best thing in JavaScript The array method reduce is the best thing in JavaScript, but it’s only existed as a native method of the language since 2009 or so, when the 5th Edition of ECMAScript was released. Before then, people would have relied on their own or other implementations. Even now, there are arguments for going elsewhere…

React: componentWillMount to be deprecated!
Our React teaching team follow developments in the Facebooks UI-creating library very closely. We update our curriculum every 2 weeks, and recently they came across an update worth sharing with everyone! This is a blog for anyone who builds User Interfaces with React! Some very important features are improving – but it’s important everyone knows…

JavaScript: The Spread Operator
The spread operator is awesome. It can do SO much — it’s efficient, readable, and can save a whole load of mess. I don’t know how you can not love it! It’s a reasonably new feature of JavaScript that came with ECMA2015 (or ES6, if you prefer, although the former is technically correct!) — or for those unfamiliar with…

Taking your JavaScript Skills to a Higher (Order) Level – Part 1
Take your JavaScript knowledge to another level, a ‘higher-order’. I remember reading about Higher Order Functions, watching videos and still not being 100% sure about what they are and what I should understand about them. Maybe it was a case of trying to run before I could walk but it all seemed so mysterious. This…

A Beginner’s Guide to Test-Driven Development
Test Driven Development (TDD) is an industry best practice, and it’s a method we teach our students from week 1 of the course. Throughout this post, I will be using Mocha as a testing framework, and Chai as an assertion library. If you’re new to programming, you’ll need to ensure you have Node installed on your machine before you read up…