DEV Community

Discussion on: Should one get good at test-last development before learning TDD?

Collapse
 
jayjeckel profile image
Jay Jeckel

I think it is definitely easier to teach writing tests if you already have code to test. After they have learned how to write tests, you can just stop there. Dogmatic adherence to writing tests first (or last or at any other preordained time) is really nothing more than cargo cult coding. Write the tests first, last, or some where in the middle, it doesn't really matter as in the end the code is the same. All that really matters is that the tests get written.

Collapse
 
toureholder profile image
Touré Holder

I see your angle. I'm a big fan of TDD, though. For me it has definitely been the best way to obtain a high quality, high coverage test suite. It also helps me to write more modular and testable code and I spend less time "thinking" about what to test. But I do agree with you that it seems easier to teach writing tests if you already have code to test. I gave a TDD course last year at work and I taught the group how to test existing code before teaching TDD.

Collapse
 
abh1navv profile image
Abhinav Pandey

But if you're doing requirement analysis before writing the code, isn't it better to start with the tests?

And as for the original question, yes, it's fine to start with writing them last on a code you're already familiar with.

Collapse
 
toureholder profile image
Touré Holder

Yeah... starting with writing tests last on existing code seems the most intuitive route to eventually learning TDD. I was curious as to whether most people who are experienced in TDD see it that way too.

Collapse
 
jayjeckel profile image
Jay Jeckel

You should be doing requirement analysis before you write any code or tests. And once you have your requirements, it doesn't matter if you write the code or the tests first.