DEV Community

Tried TDD and didn't realize the benefits? Try it the next time you get writer's block

Corey Cleary on September 21, 2018

Originally published at coreycleary.me. This is a cross-post from my content blog. I publish new content every week or two, and you can sign up to ...
Collapse
 
alchermd profile image
John Alcher

One thing that made me "get" testing is that I'm going to manually test my application anyway — why not automate it? Life is too short to click through things / run functions to see their results. Once I'm writing automated tests, I realized that I'm going to inevitably forget to write them — why not write them first? Can't be too cautious, right? Thus I'm doing TDD ever since.

Collapse
 
ccleary00 profile image
Corey Cleary

Totally, I had a similar realization when I first started getting into testing - "I know I need to write tests for this, so might as well write them first and get it out of the way"

But as I started to like writing tests more and more, "getting them out of the way" felt like less of a pain and some thing I enjoyed. For me that's when using TDD as a design tool really started to click.

Collapse
 
alchermd profile image
John Alcher

... "getting them out of the way" felt like less of a pain and some thing I enjoyed.

Same. I can say as far that if I'm not doing TDD on a project, it's not a project that I take seriously. I hope I'm not growing into a TDD zealot, but it's a thing that makes too much sense to not do.

Collapse
 
nickyhajal profile image
Nicky Hajal

This was big for me as well!

Realizing that automated testing is just the more efficient testing workflow in most cases really helped me get into it. Then having the tests in the future is just an added benefit.

What sometimes still holds me back is tedious setup + having to mock things, creating extra work.

Still trying to get more efficient at that.

Collapse
 
jsn1nj4 profile image
Elliot Derhay • Edited

I definitely needed to read this. I tried out TDD for a project a while ago and was having trouble getting it to click. Reading this post and your examples makes much more sense to me than what I've seen elsewhere.

Collapse
 
ccleary00 profile image
Corey Cleary

Awesome, glad to hear it was helpful. For me even just writing one test first a day - even if the rest were test after - helped it click even more and helped me turn it into a practice.

Collapse
 
nickyhajal profile image
Nicky Hajal

Really love the concept of using tests as a form of todo-list and as simply a way to think through/outline code in early phases.

As I mentioned in another comment, what sometimes holds me back is general setup required for testing, fake data, mocks, etc.

There's a lot of info on testing, but IMO not much on every day, practical testing practices that breaks down typical patterns and gotchas. Would definitely love more on that topic!

Collapse
 
ccleary00 profile image
Corey Cleary

"using tests as a form of todo-list" -> this is a perfect way of describing it

And I definitely hear you on there not being much content out there on real-world unit testing. When I first started learning testing this was a huge barrier for me.

I've got a whole backlog of posts I'm planning to write that attempt to target exactly the pain you described - lack of practical testing examples. It's a pain I've seen so many people have that hopefully I can help make it easier and less painful. I've got a few I've already written posted here and the future ones I'll post on my blog and here on dev.to as well!

Collapse
 
crashoverride profile image
Michael

Before I started using TDD to push through these block I used to just browse Reddit, HackerNews, etc. as a way of procrastinating. Either I was overwhelmed by a really hard problem and I didn't know where to start breaking it down, or it was just one of those days.

I'm exactly like this, but next time I will try writing a few unit tests to try to overcome coder's block.