Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Integrating TypeMock with ASP.NET Unit Tests

0.00/5 (No votes)
22 Feb 2010 1  
How to integrate TypeMock with ASP.NET unit tests

When it comes to writing unit tests for your ASP.NET pages, there isn’t much help out there. I experimented with a few open source testing tools and found some major limitations.

Both NUnitAsp and WaitN, for instance, are “client-side” tools. In other words, you have to write your tests against the actual HTML output. For example, to get the value of a textbox, you have to specify the actual HTML id of the textbox. That’s painful! Especially, since ASP.NET ends up assigning long and complicated IDs to your controls. Plus NUnitAsp is no longer being maintained or supported.

Unlike NUnitAsp and WaitN, Visual Studio ASP.NET Unit testing lets you examine the actual HttpRequest object. What this means is that you can call methods on your Page and get access to the controls within the page. Visual Studio ASP.NET is a pretty decent tool and may be the answer for you. IF you don’t need to use TypeMock, that is. But if you do, then tough luck because Visual Studio ASP.NET unit tests don’t work with TypeMock. If you give it a try, you’ll get the following exception:

Test method AzAsh.WebApp.Tests.DefaultTest.LoginNotRequiredTest threw exception: 
TypeMock.TypeMockException:
*** Typemock Isolator is not currently enabled.
To enable do one of the following:

* To run Typemock Isolator as part of an automated process you can:
   - run tests via TMockRunner.exe command line tool
   - use 'TypeMockStart' tasks for MSBuild or NAnt

* To work with Typemock Isolator inside Visual Studio.NET:
        set Tools->Enable Typemock Isolator from within Visual Studio

For more information consult the documentation (see 'Running' topic).

Check the enable property as they have suggested and you’ll notice that Typemock is enabled! So, what gives? I have no idea. But I do know that Ivonna – an ASP.NET testing tool that is being developed in partnership with TypeMock WILL let you work in conjunction with TypeMock. Like Visual Studio, it allows you to examine the intrinsic objects, such as the Page object. In addition, it’s got another neat feature that lets you inject setup code and assertions into your page’s lifecycle event handlers – very handy especially during type mocking. The only drawback is that it’s a little slow. The unit tests take a while to run.

So if you’ve been scratching your head trying to figure how to develop ASP .NET tests that can work with TypeMock, Ivonna is probably the tool you’ve been waiting for!

Post to Twitter Post to Yahoo Buzz Post to Delicious Post to Digg Post to Facebook Post to Reddit Reddit Post to StumbleUpon

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here