Unit Testing ASP.NET User Controls
page 2 of 5
by Brian Mains
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 10953/ 188

Test Setup

There are two ways to setup a unit test for a user control. The first is to have the unit test inherit from the target, as illustrated below. Note that the user control base class (AssignmentUserControlBase) is defined as an abstract class.

Listing 1

[TestFixture]
Public void AssignmentUserControlBaseTest : AssignmentUserControlBase { }

Each user control test implements the abstract properties/methods of the base class. Essentially, this custom base class sits between the System.Web.UI.UserControl class and the ASCX code-behind page. The benefit to this is that the AssignmentUserControlBase class exists in a class library, compiled as a DLL, which can be used in unit testing.

The alternative approach is to create a unit test that instantiates an instance of the user control.  I am not going to use this approach because it makes it harder to unit test the user control.  Some of the benefits will be discussed later.


View Entire Article

Article Feedback

Title:  
Name:  
Url: ( Optional )
Comment:  
Please add 8 and 5 and type the answer here:

User Comments

No comments posted yet.

Product Spotlight
Product Spotlight 
Learn More
.NET Tools
asp.net shopping cart
asp.net chart control






Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2008 ASPAlliance.com  |  Page Processed at 12/3/2008 11:53:35 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search