27

I never used an automated test mechanism in any of my projects and I feel I'm missing a lot. I want to improve myself, so I have to start tackling some issues I've been neglecting like this and trying Git instead of being stuck on SVN.

What's a good way to learn TDD? I'll probably be using Eclipse to program in Java. I've heard of JUnit, but I don't know if there's anything else I should consider.

Mike42
  • 932
  • 1
  • 8
  • 16

5 Answers5

15

You could start by working on coding katas. Pick an algorithm (e.g. decimal-to-Roman numeral conversion, scoring a bowling game, Conway's game of life, etc.) and try to use TDD to work on the solution.

Your solution structure will likely to be very simple (much simpler than your real-world production code): one class for the test fixture and one class containing the algorithm under test. And the class under test having no dependencies is another plus. You could use the simplicity of this setup to quickly get the hang of the red-green-refactor loop.

Which tool you use for your TDD katas doesn't really matter as long as you stick to the principles. However, JUnit plugin for Eclipse is very easy to use, so it's an excellent choice.

azheglov
  • 7,177
  • 1
  • 27
  • 49
8

Get familiar with AAA, read about it, read about the issues that come with test driven development ( design for testability vs high cost tools so that the design doesn't matter). Learn Dependency Injection so that removing external dependencies for testing becomes simpler.

Here's a good overview of notes I took while reading The Art of Unit Testing

http://imaginarydevelopment.blogspot.com/2010/01/unit-testing-reference.html

Maslow
  • 371
  • 2
  • 7
  • 1
    +1 for recommending The Art of Unit Testing. In my opinion one of the best books to explain unit testing without scaring away the readers. – Anne Schuessler Nov 16 '10 at 08:06
6

There is really no substitute for just grabbing a test harness (like NUnit), reading some of the literature and then getting your hands dirty.

As James T. Kirk once said, "We learn by doing."

Chris Holmes
  • 2,244
  • 14
  • 14
4

I highly recommend this book: Growing Object-Oriented Software Guided by Tests

It has a worked example running through the book and provides a very coherent view of when test should be created, what they ought to contain and how they should be constructed and refactored.

flamingpenguin
  • 2,821
  • 16
  • 12
-3

Check this link. It is Bob Martin's blog on TDD - excellent stuff to get you understand (or give you another prospective on) thinking in TDD.

Adam Lear
  • 31,939
  • 8
  • 101
  • 125
ratkok
  • 405
  • 2
  • 5
  • 2
    The blog's tag line, in Uncle Bob's own words, is "Writings on Clean Code, Design, and all things software." The blog content is much broader than OP's "any tips for beginner [in TDD]." – azheglov Nov 10 '11 at 02:27