Blog Stats
  • Posts - 18
  • Articles - 0
  • Comments - 14
  • Trackbacks - 82

 

Wednesday, May 10, 2006

Using NUnitAsp to test a secure webpage

NUnitAsp is a great tool for unit testing ASP.NET web pages.  Although NUnitAsp tests are slow to run, they're especially useful for running “web smoke tests” on a nightly basis.  (I mark every NUnitAsp class with [Category("Web Smoke Tests")] so that I can easily exclude them from my more frequent unit testing.)  On many projects, authentication is required to view a webpage.  When testing an application requiring Windows authentication, NUnitAsp can be easily configured to run as the current user logged in or as a specific domain user.

The sample test below shows how to run an NUnitAsp test using the credentials of the user that's currently logged in:

[Test]

public void TestProjectScope() {

Browser.Credentials = System.Net.CredentialCache.DefaultCredentials;

Browser.GetPage("http://localhost/WebPageToTest.aspx");

}

The sample test below shows how to run an NUnitAsp test using specific credentials.  If you're expecting the unit tests to be run from different computers, this is the recommended approach so that the tests are always run as the same person for consistency:

[Test]

public void TestProjectScope() {

Browser.Credentials = new NetworkCredential("username", "password", "domain");

Browser.GetPage("http://localhost/WebPageToTest.aspx");

}

Note that the username/password/domain must represent actual credentials - the user must really exist.

Billy

 

 

Copyright © Billy McCafferty