DEV Community

Discussion on: Test-Driven Daydreams

Collapse
 
ant_f_dev profile image
Anthony Fung

I like your thinking on this.

I didn't realise the power of writing tests upfront until I forced myself to learn TDD. I might not always adhere to the 'pure' form of TDD these days, but learning it helped me to realise a few things:

  • How to build modular SOLID code. When tests start describing all sorts of unrelated behaviour, it's usually a sign that the code could be broken into smaller modules.
  • If code design makes it hard to test, maybe it's time to make some private functions public in another module.
  • Having tests helps me to think of 'alternative' code paths, and how things might go unexpectedly.
  • A piece of code will take a certain amount of time. I can either spend it by writing a few tests, or I can continually fix bugs found in regression.
  • As this article describes, I can write tests even if no-one else on the team does. At least I'll have some verification of my work, and it can be really hard to manually test edge-case API logic.

But there are some things that I don't appreciate about the 'pure' TDD approach. I've seen some people bend the code really out of shape to accommodate writing a test. When the amount of code complexity increases disproportionately to the potential test coverage, it makes me wonder if the trade-off is worth it.

Collapse
 
bytebodger profile image
Adam Nathaniel Davis

Good points all around!

But there are some things that I don't appreciate about the 'pure' TDD approach.

Couldn't agree more. Like any methodology, it has its strengths and weaknesses. And when people twist themselves into knots trying to force a given methodology in ALL circumstances, it can get ugly.