What is Test Driven Development

Software development is a process that we can use various method to approach, Test Driven Development(TDD) is one of them.

TDD founded by Kent Beck as a part of Extreme Programming at year 2003.

Fundamentally, TDD is the concept where we write our tests before start coding and refactor our code accordingly.

TDD Workflow

Add a test

Starting to development by creating test according to our needs and spesifications.

Run all tests.

At first, we should expect them to fail, it is the reason that we need new code to meet our needs.

Write simplest code to pass the tests

In here we just need to make our test case green, we can even make it hard-coded.

All test should be okay

If there is any failed test cases repeat all the steps above

Refactor the code

Now,Refactor the code to make it clean, simple, easy to maintainable, remove if any hardcoded exists.Think about how to improve your code.
Make sure your tests are running after all changes.

Repeat

Repeat this cycle for all developments.

Advantages of TDD

  1. TDD creates a detailed specification.
  2. TDD reduces time spent on rework.
  3. We will spend less time in the debugger.
  4. We are able to identify the errors and problems quickly.
  5. We can easily tell if our last change broke the working code.
  6. TDD allows the design to evolve and adapt to your changing understanding of the problem.
  7. TTD helps simplification of the code. We will only write code in response to the requirements of the tests.
  8. TDD creates SOLID code.
  9. TDD supports a clean interface.
  10. TDD creates code that is maintainable, flexible, and easily extensible.
  11. The resulting unit tests are simple and act as documentation for the code. Since TDD use cases are written as tests, other programmers can view the tests as usage examples of how the code is intended to work.
  12. Development costs are cut.
  13. Quality is improved.
  14. Bugs are reduced.
  15. TDD will give us enough flexibility to integrate new functionality.

Limitations of TDD

Some development teams also find it hard to maintain too much unit tests, as with or without TDD many unit tests are tightly coupled to implementation of the code, they focus on testing the method rather than what it should do.

TDD In Agile

In Agile, Feedback is Critical.

The requirements can change on the way. If you want to give your customer what they still want, you need; quick feedback.

Agile development is not about running fast… It is about running fast in the right direction at a sustainable pace.

And, TDD is a way to get quick feedback.

Thanks to “Test first” approach, gives developers good understanding of what code meant to do and guidance of user functions, that is why TDD naturally fit with Agile.

Taking requirements as a base to create test cases increase the communication between developer,tester and the owner of the requirements. This will help to understanding the work better.

By creating the test first, there is no waiting time to testing to be done. It can done immedialty as it already exists. If there is any problem occured, it can send back to backlog immediately.

As you evolve the system based on feedback, bug fixes, and additional features, it tells you that the code worked and continues to work as expected.