New Best Practice Pattern

In our next release TypeMock.NET will enhance the Best Practices to use Mocks and we have added 2 new ways to use mocks

Scoping the Mocks

In this way the mocks are scoped using the following pattern

using (new MockScope()) // can set an optional timeout { // setup mocks // run tests // optional assert Assert.That(); } // mocks will be verified

The advantages of using this method are:

The disadvantage is:

Using Test Attributes*

We have added an even better way to use mocks, by defining TypeMock custom attributes to decorate the test methods.

[Test] [VerifyMocks(Timeout=150)] // mocks are always verified public void TestVerificationWithTimeout() { // setup mocks // run tests // optional assert Assert.That(): }

Once we put the [VerifyMocks] attribute on the test, the test will automatically verify all mocks.

The advantages of using this method are:

It is possible to use [VerifyMocks(Timeout=100)] that will fail the tests if not all expectations where met within the timeout.

There will also be a [ClearMocks] attribute that will always clear the mocks between tests (without verification)

These attributes can be used on the test class level too so the following will verify mocks after each test

[TestFixture] [VerifyMocks] public class TestsThatUseTypeMock { }

This will clear mock expectations after each test

[TestFixture] [ClearMocks] public class TestsTheUseTypeMock_and_ExplicitlyVerify { }

Oh, and if you are asking what testing frameworks are supported, I will surprise you and tell you that all frameworks are supported!!

*Note: The Test Attributes will require a licensed edition.

Bookmark at:
Add 'New Best Practice Pattern' to Del.icio.us Add 'New Best Practice Pattern' to digg Add 'New Best Practice Pattern' to reddit Add 'New Best Practice Pattern' to Feed Me Links! Add 'New Best Practice Pattern' to Technorati Add 'New Best Practice Pattern' to Yahoo My Web Add 'New Best Practice Pattern' to Newsvine Add 'New Best Practice Pattern' to FURL Add 'New Best Practice Pattern' to blinklist Add 'New Best Practice Pattern' to My-Tuts 

4 May 2007 | .NET Tests | Comments | Print This Post

2 Responses to “New Best Practice Pattern”

  1. 1 Eli Lopian’s Blog (TypeMock) » Blog Archive » How did we do that?!! 7 May 2007 @ 1:47 pm

    […] If you have read my previous post about the TypeMock Test Attributes you probably have noticed that the attributes are test framework agnostic! […]

  2. 2 Eli Lopian’s Blog (TypeMock) » Blog Archive » Released TypeMock 4.0 Beta 20 May 2007 @ 1:10 am

    […] The new TypeMock Decorators. […]

Leave a Reply

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

Navigation

Recent Posts

Categories

Archives

Managment