Home > ASP .NET, CodeProject, Testing, Unit Tests > Integrating TypeMock with ASP .NET Unit tests

Integrating TypeMock with ASP .NET Unit tests

February 16th, 2009 Nizar Leave a comment Go to comments

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 ID’s to your controls. Plus NUnitAsp is no longer being maintained or supported.

Unlike NUnitAsp and WaitN, VS Studio ASP .NET Unit testing let’s 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. VS Studio ASP .NET is a pretty decent tool and maybe the answer for you. IF you don’t need to use TypeMock that is. But if you do, then tough luck because VS Studio ASP .NET unit tests don’t work with TypeMock. If you give it 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 – a ASP .NET testing tool that is being developed in partnership with TypeMock WILL let you work in conjunction with TypeMock. Like VS Studio, it allows you to examine the intrinsic objects, such as the Page object. In addition, it’s got another neat feature that let’s 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!

Kick It on DotNetKicks.com Shout it
  1. virusswb
    March 13th, 2009 at 01:03 | #1

    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).

    for this problem , how solve?
    thank you for your email.

  2. Anonymous
    March 13th, 2009 at 01:06 | #2

    set Tools->Enable Typemock Isolator from within Visual Studio

  3. Nizar
    April 5th, 2009 at 08:53 | #3

    well like i mentioned in my post, you’ll have to use Ivonna to get Typemock to work with ASP .NET unit tests. once you integrate Ivonna with VS then you shouldn’t see the TypeMock.TypeMockException anymore. As an aside, I have now switched over to using ASP .NET MVC and so no longer need Ivonna and TypeMock. I now use Moq for all of my unit-testing. ASP .NET MVC is designed with testability in mind and so writing unit-tests for ASP .NET with ASP .NET MVC + Moq is both easy and significantly faster.

  4. April 7th, 2009 at 07:21 | #4

    Thank you for the post.

    A good resource for unit testing ASP.NET http://www.typemock.com/ASP.NET_unit_testing_page.php

    Note that the above resource includes links to many other useful resources

  5. February 6th, 2010 at 19:49 | #5

    Hey, I found your blog while searching on Google your post looks very interesting for me. I will add a backlink and bookmark your site. Keep up the good work!

  6. March 7th, 2010 at 08:38 | #6

    My guess is that the Visual Studio’s tests are executed in the separate process (WebDev), while Ivonna runs in the same process.

    Anyway, Ivonna is targeted at different scenarios. For example, how do you test a postback with VS Studio ASP .NET Unit testing?

  1. No trackbacks yet.