TDD vs. TFD: no more confusion!

Imenezzine
The SensioLabs Tech Blog
3 min readJun 15, 2023
Photo by Markus Spiske / Unsplash

TDD and TFD are two software development approaches focused on code quality. Although these two approaches obviously share common concepts (and a very close name), there are key differences between them.

During my participation at Symfony Live Paris 2023, I attended a very stimulating talk about testing in a Symfony application hosted by Alexandre Salomé (you can see his slides on Twitter). Following its presentation, I was confused 😐 between two concepts that are commonly mixed up by most developers: “Test-first development” and “TDD.” That’s why I decided to write this article: to clarify the difference between these two concepts 🚀.

TDD: a global approach to testing

TDD (Test Driven Development) is a test-driven development approach to design and develop code incrementally based on the RGR (Red/Green/Refactor) cycle.

  • In each iteration, when you have a failed test representing a feature to develop, you write the minimum amount of code necessary to pass the test (Green).
  • Then, if necessary, you perform a refactoring step of the production code and the test code (note that in the first iterations, it may not be necessary to refactor).

In this way, you can solve the problem progressively by splitting our functionality/need into several iterations.

Test Driven Development

TFD: focus on the final result

In contrast, Test-First Development (TFD) is an approach that consists of writing the test for a given feature, then designing and developing it in a single step. With TFD, a developer can think ahead of time about how to test the functionality he wants to implement.

By writing the test first, they can focus on the expected results rather than the implementation details. It makes it easier to design a clear and effective solution. Once development is complete, you run the test and see if it passes or not. In this approach, you can refine the test based on the implementation of the code, e.g. by adding an assertion for a behavior described by a new class.

Test-First Development

Conclusion: TDD and TFD depend on your settings

The main differences between these two approaches lie in the sequence of work and the design approach. It is important to choose the approach that is best suited to your needs and goals, depending on the context of your work 🚀

Here is a summary of these two approaches:

+----------------+--------------------------+------------------------+
| | TDF | TDD |
+----------------+--------------------------+------------------------+
| Work sequence | Start by writing one |Start by writing one |
| | or Many test(s) and then | test at a time |
| | directly to writing | |
| | all the solution code | |
+----------------+--------------------------+------------------------+
|Main objective | Design a solution to the |Design a solution to |
| | specific problem | the specific problem |
+----------------+---------------------------------------------------+
|Design approach | Focuses on |Focuses on |
| solution-oriented design |solution-oriented design|
+----------------+--------------------------+------------------------+
|Test granularity| Can have larger tests |Encourages more granular|
| |covering several functions| and specific |
+----------------+--------------------------+------------------------+
|Main advantages |Enables freer, more | Promotes a more |
| |creative and creative | controlled and |
| |design | tested design |
+----------------+--------------------------+------------------------+

--

--