1

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.

4 Answers 4

1

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

Sign up to request clarification or add additional context in comments.

Comments

0

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); 
}

Comments

0

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.

Comments

0

I was able to do this by creating a stub for the web control that I am unit testing, and calling the protected RenderContents() method, and validating the HTML:

[Test]
public void ConditionQueryBuilderTest_RendersProperHtml()
{
    var sw = new StringWriter();
    var queryBuilder = new ConditionQueryBuilderStub
    {
        ID = "UnitTestbuilder",
        QueryBuilderURL = @"\SomeAspxPage\SomeWebMethod",
        ResetQueryBuilderURL = @"\SomeAspxPage\OnQueryBuilderReset",
        FilterValuesCollection = new Dictionary<int, string> { {15, "Some Condition"}}
    };
    queryBuilder.RenderAllContents(new HtmlTextWriter(sw)); // This is a method in my stub that exposes RenderContents()

    AppendLog(sw.ToString());

    Assert.AreEqual(ExpectedHtml, sw.ToString());
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.