DEV Community

Discussion on: Bad Test, Bad

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 :)