Decorator feature enhancement

[Cross Posted in TypeMock Insider Blog]

Typemock-Isolator has a little know Decorator feature that allows developers to simply add capabilities to their test framework (all test framework).

Using this feature Typemock-Isolator creates the [VerifyMocks] decorator that automatically verifies the mocks at the end of your tests.

To create a custom decorator simply extend the DecoratorAttribute and implement the Execute method.

public override object Execute()

{

    // Trace start of method

    Console.WriteLine(“Entering Method:”+

     OriginalMethod.ToString());

    // Execute the original method

    return base.CallDecoratedMethod();

}

To support multiple decorators on the same test method, Typemock-Isolator makes sure that even if a developer forgot to call CallDecoratedMethod() the test method will still run. This is done by calling the decorated method if it wasn’t explicitly called.

We discovered that some Decorator implementers want more control and need to explicitly make sure that the test method was NOT called.

A new API was added in version 4.2 to do just that.

DontCallDecoratedMethod()

Once this is called (inside Execute), the decorator mechanism will not call the test method.

Of course if there is another decorator on the test method that calls CallDecoratedMethod() the test method will be executed.

Bookmark at:
Add 'Decorator feature enhancement' to Del.icio.us Add 'Decorator feature enhancement' to digg Add 'Decorator feature enhancement' to reddit Add 'Decorator feature enhancement' to Feed Me Links! Add 'Decorator feature enhancement' to Technorati Add 'Decorator feature enhancement' to Yahoo My Web Add 'Decorator feature enhancement' to Newsvine Add 'Decorator feature enhancement' to FURL Add 'Decorator feature enhancement' to blinklist Add 'Decorator feature enhancement' to My-Tuts 

7 February 2008 | .NET Tests | Comments | Print This Post

Leave a Reply

  1.  
  2.  
  3.  
Search Eli Lopian’s Blog (TypeMock)

Navigation

Recent Posts

Categories

Archives

Managment