Sunday, January 23, 2011

Test Driven Development . Does Your code have GUTs


Lets try to put in simpler sentences on what is Test Driven Development .

  1. Understand the scope of your feature or requirement
  2. Create a test that you know will fail
    • Call a method that doesn't exist or behave correctly yet
    • This is important because you don't want your tests to pass by accident
  3. Make your failed test pass by adding a minimal amount of code
    • Change the code so that it will pass, but don't go overboard
    • Writing minimal code helps enforce not writing code you don't need
  4. Modify your code to make any necessary improvements
    • This is the point at which you can refactor into methods, rename variables, redesign your interfaces, and so on

Characterstics of Good Unit Test ( GUTs)
---------------------------------------------
  • Runs fast ..simple it should run really fast.
  • Keep the unit test  scope simple and clear. If the test fails, it's obvious where to look for the problem. Use few Assert calls so that the offending code is obvious. It's important to only test one thing in a single test.
  • "It works on my machine " syndrome : It should Run and pass in isolation. If the tests require special environmental setup or fail unexpectedly, then they are not good unit tests. Change them for simplicity and reliability. Tests should run and pass on any machine. It
  • Mock and Stub : Often uses stubs and mock objects. If the code being tested typically calls out to a database or file system, these dependencies must be simulated, or mocked. These dependencies will ordinarily be abstracted away by using interfaces.

No comments:

Post a Comment

subversion video