Testing ASP.NET Pages

I've been working on getting ad hoc tests working with ASP.NET.  In order to work, the code behind class must be annotated with several attributes.  They let the test runner know which page to render, what query string to use and when to run the test.  The test can be run during any page event (Init, Load, DataBinding, PreRender etc.).  For example, say you right click on and run the following 'test()' method....

[Page("Test.aspx")]

public class Test : System.Web.UI.Page

{

private void Page_Load(object sender, System.EventArgs e)

{

Debug.WriteLine("Page_Load");

}

 

[Query("name=value"), Event("PreRender")]

private void test()

{

Debug.WriteLine("debug output...");

Debug.Assert(Request.QueryString["name"] == "value");

}

 

#region Web Form Designer generated code

}

The following would appear in the test output window...

------ Test started: Assembly: TestWebProject.dll ------

Page_Load
debug output...
file:///C:/CVSHOME/NUnitAddin/TestWebProject/Test.aspx.htm

1 succeeded, 0 failed, 0 skipped, took 0.00 seconds.

---------------------- Done ----------------------

I would be interested to know how people are testing their ASP.NET pages today. I'm also open to suggestions as to how this feature should work. At the moment it's just for individual ad hoc tests. I'm wondering how to enable it for whole test suites. Drop me a line if you have any suggestions or would like to play with the latest revision (I'm afraid a build still isn't up).

P.S.  I'm still looking for someone to help test the Mono & Rotor support.  I need someone to go though the configuration procedure to flush out any issues.  Does anyone fancy a play with Mono?  ;o)

2 Comments

  • I'm doing it by having NUnit on the server open and watching my assembly. I have all my code that I want to test in utility functions and then some extra testing classes. As I develop on my laptop, I turn my chair about 30 degrees to the right and click the run button with the mouse. Kinda inconvenient...but c'est la vie, for now at least. ;) *Hint hint, I want that latest revision...*

  • This page seems broken. Is it?

Comments have been disabled for this content.