This project is read-only.

ProMesh.NET Quick Walkthrough - Part 9 - Unit Testing

One of the most powerful and useful features of ProMesh.NET is its built-in offline mode for unit testing. ProMesh.NET allows you to write methods that mimic a user navigating through the site. This allows you to write unit tests for your complete website, which is almost impossible with ASP.NET or other frameworks.

Consider the following scenario we want to test:
  • Navigate to a page which is not accessible for a user who is not logged in yet
  • Check if the application correctly redirected us to the login page
  • Enter the login and password of a known user
  • Check if the application redirected to the main page for authenticated users

This is the NUnit test fixture you could write for testing the scenario described above:

public class WebSiteTest
   public void TestLogin()
            OfflineWebSession webSession = new OfflineWebSession();

            webSession.FollowRedirects = true;

            // try to open a page not allowed for anonymous users

            // check if page was redirected to the login page
            Assert.AreEqual(webSession.CurrentPage, "/login.ashx");

            // enter the login and password on the login page
            webSession.PostData["LOGIN"] = "";
            webSession.PostData["PWD"] = "mymostsecretpassword";

            // do login

            // check if the page was redicted to the "My Account" page

            // check if the correct user is logged in

            // ALL TESTS PASSED

You can see right away that the possibilities are endless. You don't have to do anything specific in your application to allow unit testing. Just create a test fixture and perform the actions you want to test. That's it.

Last edited Aug 2, 2007 at 9:46 PM by activa, version 3


No comments yet.