DEV Community

Discussion on: Bad Test, Bad

Collapse
 
afcjunior profile image
Adalberto Camacho Jr.

Very well written. I loved how you gave bad examples and proceeded to correct them.

And you raise some good points too. I found many testing patterns I learned from experience that I wish someone had told me about when I was just getting started with TDD. Especially the one about not giving too much thought to the DRY principle during tests.

Collapse
 
rfornal profile image
bob.ts

I was in the same boat and recently have been mentoring an organization on testing ... prompting this article. Thanks!

Collapse
 
jamesthomson profile image
James Thomson

One of the hardest parts I found about TDD was knowing exactly what to test.

You start off thinking you must test every little bit of code, but this just creates major overhead and often quite brittle tests. I've come to the conclusion that it's better to think about it as input/output.

Only testing for what's coming in and what's going out. The internals of how we get that expected output aren't necessary to test. This has helped greatly when writing tests and hopefully is correct.

Other than that, TDD has really helped to encourage keeping functions simple and modular. When something becomes (or looks like it's becoming) difficult to test, it often means the function is becoming too verbose and should be split up into smaller more manageable/testable pieces.

Collapse
 
rfornal profile image
bob.ts

Very well stated!

Thread Thread
 
jamesthomson profile image
James Thomson

Thanks! That's reaffirming :)