TDD Practices Debate

Discussions center on Test-Driven Development (TDD), debating whether tests must be written before code, adherence to the red-green-refactor cycle, and its value versus alternatives like prototyping or parallel test writing.

➡️ Stable 0.5x Other
2,580
Comments
20
Years Active
5
Top Authors
#2087
Topic ID

Activity Over Time

2007
7
2008
37
2009
64
2010
67
2011
97
2012
111
2013
144
2014
140
2015
84
2016
175
2017
218
2018
114
2019
223
2020
143
2021
118
2022
261
2023
217
2024
119
2025
224
2026
17

Keywords

AI TDD TFD YourThing BS BEFORE CSV OOP simonwillison.net i.e tdd tests code write test write tests writing unit tests refactor unit

Sample Comments

majikandy Aug 19, 2022 View on HN

It sounds a little like you are trying to write all the tests to the spec up front? With TDD you are still allowed to change design choices as you go and as you realise how you want it to behave. That’s why the tests are one by one. In my experience, TDD carries the most value when you really don’t know where you are going, you write the first test and you start rolling, and somehow you end up at your destination and people think you were good at writing code but actually the code was writing it

ulisesrmzroche Mar 6, 2014 View on HN

You're not doing Test-Driven Development if you're writing code and then writing tests, though. You must write your test first, and only after you see it failing, write the code to make it pass. You have to stick to this cadence if you want to put TDD in practice.

hackerm0nkey Nov 16, 2019 View on HN

Yes, it's a welcomed side effect of TDD'ing, TDD is more of a design tool. But also I have experimented with writing tests before/after the implementation. Code with tests written first seemed to always be just to the point and get one in the mindset of thinking ahead of your edge cases and pin them down

norswap May 17, 2013 View on HN

Isn't TDD all about writing tests before coding?

gregw2 Aug 17, 2023 View on HN

With TDD you write tests first, then ensure your tests fail, then write code, ... for the reasons you mention.

4140tm Sep 28, 2021 View on HN

You don't need precise specs to practice TDD. If you have idea of the code you need to write, you can write the test for it beforehand - no matter how often someone might change their mind about the app.Doing so would actually make your life a lot easier when it's time to alter functionality, because now you have well tested and testable code. Code that is written to be tested is usually a lot easier to reason about, to change and extend.If you do it in concise manner and test be

sanderjd May 28, 2020 View on HN

I think TDD purists seem to see no point in unit tests that are not written before the code. That is, if the unit tests were not used to drive the design and implementation of the code under test, they are useless. I find a lot of value in the test driven approach, but this purist view does not make sense to me. I sometimes, or often, write the code first (being able to do so in a repl in languages that support that is even better), when I find it easier to think through the problem in terms of

bitwize Mar 18, 2025 View on HN

TDD has always meant to write your tests first. Red, green, refactor. If you're not doing TFD, you're not doing TDD; you're just developing with tests. TDD is test-driven precisely because all implementation code is written to make some failing test pass. Code not so written is by definition broken and does not make it into production. (If you need to try out an idea without writing tests first, that's called a spike and it should be thrown away after proving what you

onion2k Feb 12, 2023 View on HN

TDD can be great if you know exactly what you're building and what you must test for, but it gets in the way when you're rapidly prototyping and exploring.It sounds like you're making the mistake of thinking that TDD means writing the tests first. That's not quite right but it's understandable that lots of people believe it given the way TDD is usually discussed.In TDD you should be writing one test first. Then you write enough code to make that test

telesyasmin Jul 3, 2024 View on HN

Write tests first, then code to make them pass. Catch bugs early and create resilient, optimized code. Use small, incremental cycles for frequent feedback. Embrace micro-testing and best practices for successful TDD!