Leave a comment

TDD – How it works and what it gives you

TDD is frequently discussed in the software industry, but how many people actually do this properly? A lot less than you think! Ask someone what TDD means and if they lack knowledge they’ll simply say “unit testing” or worse still won’t be doing it at all. So this is a quick guide:

  • TDD basics – How you do it
  1. You write the test first which fails (there’s no code written yet). Hence you’ve thought about the functionality before you start the implementation
  2. Then plug in the code until the test passes
  3. TDD tests are at a unit level i.e. low level code such as a class. They’re not for full UI testing and won’t give you end to end functionality
  • TDD –  Positive, Negative & Exception testing
  1. Positive – If you have the valid values of 18 to 65 going into your code, you can test some of the values between this range. This is positive testing. As a helpful hint consider the boundary tests when you do this, try the values of 18 and 65, does it still work?
  2. Negative – What about seeing how the code handles the value of 16, does it the code handle this or does it crash? You can make sure you’re error handling works properly this way.
  3. Exception – How does the code handle a letter being passed to it? Passing “H” is obviously nonsense but you can code to cope with this. Now think further, what if someone passes a negative number?
  • What TDD does not do
  1. If I have my whole system under unit test does this mean my system will definitely work? Err no, but why is this? If one piece of code takes the valid values of 18 to 65 then outputs the word “Valid” to pass to the next object your tests will be passing. However what happens if the next object is expecting a “V” not the word “Valid”, oops your system is now failing when you plug it together. So the integration between components is not solved by TDD.
  2. TDD may not make sense to a business person. TDD tests are not necessarily in “business flow” language and can be so abstracted from the business language that only developers can read them. Imagine a complex calculation on tax, you plug in your wage and out pops the amount you are expected to pay, as a business user do I really care what the data loader is doing behind the scenes? The developer does, but the business person won’t i.e. put all these tests together and output them, now consider how does a business user know what’s being tested and what isn’t?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: