Mar 4, 2005 / NUnitASP Problems
1 commentsTests 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() { SetInnocentState(); 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); Browser.GetPage("http://tp/Tp.Web/Project/1/Planning/UserStories/List.aspx"); } [Test] 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); } [Test] 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.
1 Comments:
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.
Post a Comment
<< Home