Eden Ridgway's Blog

.Net and Web Development Information

  Home :: Contact :: Syndication  :: Login
  105 Posts :: 1 Stories :: 78 Comments :: 3 Trackbacks

Search

Article Categories

Archives

Post Categories

Development

General

So in my quest to get a practical solution to testing before developing, I turned to the experts for advice. The article Test First Guidelines had the following advice:

  • If you find it difficult to unit test a system, then you may be over complicating the design
  • The name of each test should match the requirement it is testing
  • Write the simplest code to pass the test and add additional tests if you know that the code will have to accommodate for other situations
  • A test should look similar to sample code - it should be concise and obvious
  • Perform one test -> code -> simplify cycle at a time. Don't write a whole bunch of tests and then code them all at once.
  • If uncertain about whether or not the code will handle a certain situation, write a test
  • A typical test cycle should take around 10 minutes
  • Do not fix a bug until you have written a test to demonstrate the bug first.

When developing the approach suggested is as follows:

  1. You cannot write any code for the system until you have a failing test.
  2. Initially you should have a unit test that does not compile because you have not written the corresponding application logic yet.
  3. You then write enough code to get the test to compile. In other words just create the required interface for the test.
  4. Then fill in the logic, test and refactor. This step continues in a cycle until you are satisfied.

Then when dealing with whether or not you have gone far enough with your unit tests, an approach called Mutation Testing comes in to play. The idea is as that if you modify your code, say comment out a line, at least one of your tests should fail. If it doesn't it could mean one of two things:

  1. Your test coverage is inadequate and more tests must therefore be added
  2. The line of code should not have been there in the first place - simplicity of the code is one of the Key Performance Indicators of this approach.

There is a tool called Nester which is a "unit test tester". My colleagues and I have previously joked about infinite unit tests based on this principle, I just didn't realise how close to the truth we were :). The idea of the tool is to make small changes or mutations to your code to see whether or not the tests fail.

I think for now we'll just try to get the initial testing approach right.

posted on Wednesday, July 13, 2005 1:59 AM
Comments have been closed on this topic.