Click here to Skip to main content
15,881,757 members
Articles / Web Development / ASP.NET

Integrating TypeMock with ASP.NET Unit Tests

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
22 Feb 2010CPOL2 min read 10.6K   3   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

This article was originally posted at http://nizarnoorani.com/index.php/archives/111

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) NCube, Inc.
United States United States
Nizar Noorani is an independent software consultant. He provides services in the areas of web applications and systems architecture, analysis, design and development. Although proficient in a variety of technologies, he specializes in the .NET technology. He can be reached at nizar.noorani@gmail.com.

Comments and Discussions

 
QuestionIvonna has a new home Pin
Artem Smirnov12-Aug-11 22:07
professionalArtem Smirnov12-Aug-11 22:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.