Cover image for the article Simple 6 step process to Test Driven Development

Simple 6 step process to Test Driven Development

An introduction to Test Driven Development, its six-step process, advantages and disadvantages, and how it compares with Behaviour Driven Development.

Software EngineeringVishav Premlall4 min read

What is TDD?

Test Driven Development is a process whereby you would test first, then implement. Unit tests come first, actual implementation code next, followed by integration tests. Tests which 'drive' implementation is the basis of TDD.

Process Of TDD

TDD methodology follows a very simple 6 step process:

1. Write a test case: Based on the requirements, write an automated test case.

2. Run all the test cases: Run these automated test cases on the currently developed code.

3. Develop the code for that test case: If the test case fails, then, write the code to make that test-case work as expected.

4. Run test cases again: Run the test cases again and check if all the test cases developed so far are implemented.

5. Refactor your code: This is an optional step. However, it's important to refactor your code to make it more readable and reusable.

6. Repeat the steps 1-5 for new test cases: Repeat the cycle for the other test cases until all the test cases are implemented.

R – G – R – R

  • Red – write a failing test
  • Green – make it pass
  • Refactor – remove wasteful code and ensure that the test you wrote still passes – this promotes leaner code
  • Repeat until your task is completed.

Advantages

  • In essence, the development cycle quickens, as developers have much quicker feedback on mistakes and bugs.
  • Tests can serve as documentation to new coming developers.
  • Increasing returns - At first, learning and applying TDD will be challenging, but in the long run it will be a benefit.
  • Bugs will pop up at development time rather than after a deploy, or worse, when the user gets the system.
  • There are frameworks which allow mocking of exterior components or libraries, allowing you to focus solely on what you are creating.
  • Supports agile principles 100%.

Disadvantages

  • Initial 'cost' is generally high.
  • It is quite a mind shift for waterfall developers.

Agile software testing

TDD facilitates Agile. Smaller pieces of functionality are taken on in sprints. Unit tests are written upfront. Implementation is done, and system testing is performed. These system tests can be completely automated.

What is Behaviour Driven Development (BDD)?

  • BDD is a flavour of TDD.
  • Behaviour driven development.

Scenario. Walking to this very room. With TDD we have assertions to cover each point of significance, with BDD we only care about the result of the operation.

So, a TDD solution for getting to this room would be getting up from your chair, then walking in the direction of the meeting room. Each turn can be placed into a test on its own. In fact, every single move can be an assertion or test.

TDD Vs BDD – Key Differences

Test Driven Development (TDD) vs Behavior Driven Development (BDD)

  • The process starts by writing a test case. | BDD: The process starts by writing a scenario as per the expected behaviour.
  • TDD focuses on how the functionality is implemented. | BDD focuses on the behaviour of an application for the end user.
  • Test cases are written in a programming language. | Scenarios are more readable when compared to TDD as they are written in simple English format.
  • Changes in how the application functions impact a lot on the test cases in TDD. | BDD scenarios are not impacted much by the functionality changes.
  • Collaboration is required only between the developers. | Collaboration is required between all the stakeholders.
  • Might be a better approach for projects which involve API and third-party tools. | Might be a better approach for projects which are driven by user actions. For eg: e-commerce website, application system, etc.
  • Some of the tools which support TDD are: JUnit, TestNG, NUnit, etc. | Some of the tools which support BDD are SpecFlow, Cucumber, MSpec, etc.
  • Tests in TDD can only be understood by people with programming knowledge. | Tests in BDD can be understood by any person including the ones without any programming knowledge.
  • TDD reduces the likelihood of having bugs in your tests. | Bugs in tests are difficult to track when compared to TDD.

Create unit tests to help keep your code working correctly through incremental code changes. There are several frameworks that you can use to write unit tests, including some developed by third parties. Some test frameworks are specialized for testing in different languages or platforms. Test Explorer provides a single interface for unit tests in any of these frameworks. More Here:

Walkthrough: Test-driven development using Test Explorer

Keep reading

More thought leadership.

Automation & Integration1 min read

Stop trying to build one genius agent

Everyone wants the one super-agent. It falls over. The teams winning with agents in 2026 build small crews of specialists with a manager.

Read article
AI1 min read

Most agentic AI projects will be quietly cancelled. Don’t be one of them

Gartner expects over 40% of agentic AI projects to be cancelled by 2027. The survivors share one dull trait: they chase value, not novelty.

Read article
AI2 min read

The day your AI stopped answering and started doing

Generative AI answered questions. Agentic AI takes action. When a wrong move books the flight or issues the refund, autonomy needs a blast radius.

Read article

Get in touch

Got a problem worth solving?
Let’s talk.

Send us the gist of what you are trying to do. The right person from First Digital will be in touch within a working day.