Blog Stats
  • Posts - 18
  • Articles - 0
  • Comments - 42
  • Trackbacks - 76

 

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


Feedback

# re: Using NUnitAsp to test a secure webpage

Gravatar Thanks for posting that. It was very helpful to me. 7/10/2007 9:08 AM | Rich

# re: Using NUnitAsp to test a secure webpage

Gravatar Nice idea, thank you! 8/17/2009 12:11 AM | Ilshat

Post a comment





 

 

 

Copyright © Billy McCafferty