5 ms·
>You can have tests without TDD ? I've worked on several projects without this and the tests done without TDD tend to be of higher quality. I noticed a common
by crdoconnor 10y ago
>You can have tests without TDD ?
I've worked on several projects without this and the tests done without TDD tend to be of higher quality.
I noticed a common anti-pattern of "write the code, run the code, copy the output of the code, paste it into a test and write an assert to check that the output was precisely what came out".
This was brittle, it killed the self-documenting aspect of the tests and it often concealed various bugs.
As soon as the same team members started writing the test first, it stopped happening.
I also personally felt better about doing this since it made it easier to correct API design mistakes before implementing the code and baking them in.
- rubber_duck 10y ago>I also personally felt better about doing this since it made it easier to correct API design mistakes before implementing the code and baking them in. How do you know you made API mistakes from writing unit tests ? API mistakes become apparent when you integrate stuff and use the API in conjunction with other things (using API in isolated scenarios like unit tests is not really insightful you can figure out those flaws just by looking at the API). This is my primary criticism of TDD - you write tests around the initial bad API and you end up keeping that bad design because you already spent so much time testing that. Implementation errors caught by unit tests are cheaper to fix afterwards then design errors. My approach is hack together a POC -> refactor that and write tests. If you discard the POC then TDD makes sense to me.
- crdoconnor 10y agoI usually don't do unit test driven development actually. I typically do integration test driven development where the integration test sets up an environment where the code is either interacting with the real thing or a realistic mock version. I don't find unit tests all that useful for integration code - either as tests that find bugs or for doing TDD.
- piaste 10y ago> I've worked on several projects without this and the tests done without TDD tend to be of higher quality. Do you mean "with TDD", by any chance? The rest of your post says that you observed better results when tests were written before the code (rather than later). But as far as I understand, writing the tests before the code is indeed one of TDD's commandments.
- crdoconnor 10y agoYes. Dumb mistake.