NUnitASP Problems

I’ve tried NUnitASP to test ASP.NET web pages in TargetProcess project. As usual, there are some problems with tool adoption. All these issues have been resolved, but I am not satisfied with solutions and stop using NUnitASP for now. I want to find a better way.

Tests Independence & Database State

To keep tests independent, web application should be in known initial state before every test

The TargetProcess system uses database, so the database should be in the same state before each test. I can’t find a better way than executing bat file from command line in [SetUp] method. The bat file contains something like this:

osql -U sa -P -d dbname -i D:\TargetProcess\src\Tp.Model\Sql\testData.sql

This works. Not as fast as I want, but I can wait a minute or two. When database become bigger, this solution might be unacteptable.

Dynamic Controls Insertion and NUnitASP

Most of the server controls inserted dynamically on run-time in TargetProcess. This cause additional problems, since controls ids may change. For example, new TargetProcess’ module will insert additional control on dashboard. And I should update many already defined Ids in tests. Here is code sample:

protected override void SetUp()

  control = new UserControlTester("_ctl4", CurrentWebForm);

  ddFilterByIteration = new DropDownListTester("ddFilterByIteration", control);
  btnUpdate = new ButtonTester("btnUpdate", control);

  dgUserStories = new DataGridTester("dgUserStories", control);
  row = dgUserStories.GetRow(0);

  ddIterations = new DropDownListTester("ddIterations", row);
  lbChangeStatus = new LinkButtonTester("lbChangeStatus", row);
  lbDelete = new LinkButtonTester("lbDelete", row);


public void ListView()
   string[] expected = new string[]
       {"Text. Will not check it", "12", "Great"};

   AssertEquals(expected[1], dgUserStories.GetRow(0).TrimmedCells[1]);
   AssertEquals(expected[2], dgUserStories.GetRow(0).TrimmedCells[2]);
   AssertEquals("- Iteration? -", ddIterations.SelectedItem.Text);
   AssertEquals("Done", lbChangeStatus.Text);

public void FilterList()
   ddFilterByIteration.Items[1].Selected = true;
   AssertEquals("Iteration #1", ddIterations.SelectedItem.Text);
   ddFilterByIteration.Items[0].Selected = true;
   AssertEquals("- Iteration? -", ddIterations.SelectedItem.Text);

In code control = new UserControlTester(“_ctl4”, CurrentWebForm) real base control id is “_ctl4”. But when add new control on the top of this, its id will be “_ctl5”. This is a major issue for now.

One thought on “NUnitASP Problems”

  1. Check out Ruby/Watir. We’re using it at our company, and while it takes a little work to get configured (mostly it’s because we used Cassini instead of Apache), it works pretty well.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s