HACKER Q&A
📣 suralind

Practical Guide to TDD?


I have a problem - I am really bad at writing tests. It's not that I can't write them - I always forget to..

The idea of TDD was always interesting to me and I've tried to implement it into my routine a couple of times in the past, but my experience was always the same, which was, in short, slow iteration cycle.

Can you share some practical guide/tips or an article that's good for starting out with TDD?


  👤 mindcrash Accepted Answer ✓
The book mentioned below is basically the defacto book on TDD; but if you are in the .NET ecosystem (or know how to read C# pretty well) and want to read a nice practical one I can really recommend The Art Of Unit Testing published by Manning: https://www.manning.com/books/the-art-of-unit-testing-second...

Also note that these days all popular commercial IDEs (Visual Studio, IDEA, Rider) have great builtin support for TDD (for example: automatically running tests after code changes) so manually doing things and thus slow development are a thing of the past...


👤 mtmail
Related from the last 30 days

Ask HN: How would one start doing TDD “properly”? https://news.ycombinator.com/item?id=32453407

Ask HN: Seriously, how do you TDD? https://news.ycombinator.com/item?id=32712909


👤 PaulHoule
You have to find some answer that makes you feel like the tests are worthwhile and not just busywork.

In Java I see it as an competitor to the ‘mess around with the Python CLI’ approach, In the IDE it is as quick to cycle and you can breakpoint w/ the debugger. If you have some question about how it works, you can answer the question and produce a test that is checked in.

In that way you document the API.


👤 idontwantthis
I don't think you can do better than the original https://www.amazon.com/Test-Driven-Development-Kent-Beck/dp/...

To summarize:

1) Write a failing test 2) Make it pass as quickly as possible 3) Repeat and refactor as necessary