Geeks With Blogs
Rajesh Pillai My experiments with mvc, jquery, wpf, silverlight, sharepoint, tdd and design patterns.

Here's a quick notes from the TDD session which I conducted some time back.


  • Writing test before writing production code.
  • Design as you go along.
  • Follow Red-Green-Refactor paradigm


  • Spot design flow early.
  • Test before the production code is built.
  • Identify poort requirements or requirement gaps.
  • Reduced testing time.
  • The test forms the functional document for your code.
  • Quickly identify bugs.
  • Reduces the cost of bugs in the long run.
  • Low level regression test suite.

Road blocks to TDD

When doing TDD the following road blocks you may hit.

  • Real objects are slow
  • Ral objecs are difficult to mock.
  • Rad object may be unavailable.
  • Real object may be costly.
  • Real object does not yet exits.

Here "Real Object" is the object under test.

The solution - Enter Mocking

  • What is a mock object?
    • Mock objects are stand-in-object for real object.
  • Use of mock object
    • Real object has non-deterministic behaviour.
    • Real object is slow.
    • Real object is difficult to setup.
    • Real object is expensive.

Rhino Mock (The mocking framework)

  • A dynamic mock object framework for the .NET platform.
  • Objective is to ease testing by allowing the developer to create mock implementation of custom
    objects and verify the interactions using unit testing.

Stubs and Mocks

  • A mock is an object that we can set expectations on, and which will verify that the expected actions have
    indeed occurred.
  • A stub is an object that you use in order to pass to the code under test.  You can setup expectations on it,
    so it would act in certain ways, but those expectations will never be verified.  A stub's properties will
    automatically behave like normal properties and you cann't set expectations on them.
  • If you want to verify the behaviour of the code under test, you wil use a mock with the appropriate
    expectation and verify that.  I you want to just pass a value that may need to act in  a certain way, but isn't the
    focus of the test you will use a stub.

IMPORTANT: A stub will never cause a test to fail.

Rhino Mocks - 1

  • CreateMock / StrickMock
    • For strict mockign
  • DynamicMock
    • Flexible
  • PartialMock
    • Mock concrete class
    • Only  mock virtual methods

AAA approach

  • A - Arrange
    • Arrange your tests.  Setup your values.
  • A - Act/action
    • Execute the testing condition.
  • A - Assert
    • Assert on expectations.


Happy TDD'ing....

Posted on Saturday, November 28, 2009 4:47 PM TDD | Back to top

Comments on this post: Some notes from my tdd session

No comments posted yet.
Your comment:
 (will show your gravatar)

Copyright © Rajesh Pillai | Powered by: