Geeks With Blogs
Billy McCafferty whatever (but really just .NET)

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

Posted on Wednesday, May 10, 2006 7:48 AM ASP.NET , C# | Back to top


Comments on this post: Using NUnitAsp to test a secure webpage

# re: Using NUnitAsp to test a secure webpage
Requesting Gravatar...
Thanks for posting that. It was very helpful to me.
Left by Rich on Jul 10, 2007 9:08 AM

# re: Using NUnitAsp to test a secure webpage
Requesting Gravatar...
Nice idea, thank you!
Left by Ilshat on Aug 17, 2009 12:11 AM

# re: Using NUnitAsp to test a secure webpage
Requesting Gravatar...
Need to secure my webpages more.
Left by Mike | 25 People Search Engines on Aug 30, 2010 2:34 PM

Your comment:
 (will show your gravatar)


Copyright © Billy McCafferty | Powered by: GeeksWithBlogs.net | Join free