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.