views:

275

answers:

3

I am just learning about Unit Testing. I am using NUnit to build tests for a VB.NET project.

The project I'm working on is part of a framework which will be used by people who build ASP.NET websites. It includes a base class (which inherits System.Web.HttpApplication) that users of my framework will inherit their application class from.

The project also contains a number of composite controls.

I can't quite work out at the moment how you would go about writing tests for either the application base class or any of the composite controls.

In the case of the application base class, should the Unit Test project include a class which inherits from it and then test against that?

Any pointers would be appreciated!

Thanks.

A: 

It's no longer maintained but there is NUnitAsp.

[Test] 
public void TestExample() 
{ 
   // First, instantiate "Tester" objects: 
   LabelTester label = new LabelTester("textLabel"); 
   LinkButtonTester link = new LinkButtonTester("linkButton"); 

   // Second, visit the page being tested: 
   Browser.GetPage("http://localhost/example/example.aspx"); 

   // Third, use tester objects to test the page: 
   Assert.AreEqual("Not clicked.", label.Text); 
   link.Click(); 
   Assert.AreEqual("Clicked once.", label.Text); 
   link.Click(); 
   Assert.AreEqual("Clicked twice.", label.Text); 
}
eed3si9n
A: 

This is only a partial answer. This is the way you'd do this type of a thing in django. I imagine there is something similar in ASP.NET. For testing the client-side code there are things like jsUnit.

rz
+1  A: 

I would test the application base class indirectly by creating a subclass and testing that, just as you said.

For the controls, I would use Selenium: http://selenium.seleniumhq.org/.

Helen Toomik