Ask HN: Books on Unit Testing and TDD?

I'm in a situation where I understand the importance of unit testing and how TDD works, but in practice I don't actually get to do it much. The technology I'm working in isn't really testable in this way.

That being said I'm interested in locating some reading material on these topics that don't just cover the basics, but do so with a little more depth so I can hopefully glean some of the senior level experience I'd get if I was actually doing it regularly.

7 points | by Desafinado 1 day ago

4 comments

  • fullStackOasis 5 hours ago
    I like JUnit Recipes. While it's written years ago for Java, I like how you can jump around within each chapter and read about different problems that can be solved by running tests. Just reading the problems and the description of each recipe is enough to help you develop a test-driven mindset. You don't have to read any of the code samples if you don't want to. https://www.manning.com/books/junit-recipes

    Disclaimer: I'm a friend of the author, so I'm biased, but I really do think the book is good.

  • voiceofunreason 15 hours ago
    My recommendation: you should probably start from _Working Effectively with Legacy Code_ by Michael Feathers.

    The best "let's do something not trivial" TDD book is probably still _Growing Object Oriented Software, Guided by Tests_ by Steve Freeman and Nat Pryce.

    Most of the "more than the basics" topics are the same kinds of practices that were considered "good design" whether you were using TDD or not. For example, Parnas 1971, Berard 1993, John Carmack 1998 ("Time is an input...."), and so on.

    If you are interested in more than the basics on TDD, the right starting point is _Test Driven Development by Example_ by Kent Beck, which while a bit thin on examples actually covers a nice variety of more advanced topics (although not in great depth). If you are going this route, you should pair that with Beck's 2023 essay "Canon TDD".

    • DerArzt 43 minutes ago
      I would give the book by Beck a bit of lenience as it was the first book on the subject at a time that testing frameworks weren't as ubiquitous as they are today.

      It's still a good foundational book to start with though.

  • ossm1db 1 day ago
    "Essential Test-Driven Development" by Rob Myers was just released: https://www.amazon.com/dp/0134494156
  • jamesliudotcc 1 day ago
    There is this free book, https://www.obeythetestinggoat.com/, which is also available in print for O'Reilly. Manning has https://www.manning.com/books/unit-testing.