After using NUnitAsp to do lots of testing over the past several
weeks, I've learned a few tips that I would like to pass on.
These are not “how-to code NUnitAsp“ but more of “how to keep your hair
with NUnitAsp.“
- Test for the URL of the page you expect first. True
to Test-Driven Development, make sure that the browser’s current URL
local path is what you expect (i.e., /myApplication/startPage.aspx). Doing so will save you a lot of headache when trying to figure out why a certain control is not visible. This leads us to the next guideline…
- Prefer tests of the visibility of a control when true. Successful tests for false visibility can be misleading. For example, if you misspell the control’s rendered name, a test for visibility = false will still pass. Tests
for false visibility are useful when used in conjunction with tests for
true visibility, i.e. to ensure that certain controls are shown while
others are not.
- Make sure the web project you are testing is working before attempting to test with NUnitAsp. You can make sure it works by navigating to it at http://localhost/AppName (or wherever you are testing against it, it does not have to be localhost).
- Be prepared to wait. NUnitAsp tests are not fast. The bigger the project, the longer the initialization time. You
can speed things up by opening the application in a web browser, which
forces .NET to JIT compile all the class files in that directory. But that only works until the next build.
- The more controls you test, the more brittle your tests are. Try to test only those controls that are the centerpiece of the page. If you start writing visibility asserts for every image or hyperlink, when the page changes those tests will break. Keep the focus on the important things, the inputs and events (i.e., textboxes and buttons). A useful develop-for-testing tip is to use labels to display text instead of <% =databoundText %>. Then the NUnitAsp tests can test to see if the label is there, regardless of the text.
- Overload the ImageButtonTester.Click(x, y) event. When
testing an ImageButton with an ImageButtonTester, the Click event takes
two integers as the x and y coordinates of the ImageButton click. Unless the button does different things based on the x and/or y values, you are just going to be writing a lot of meaningless myButton.Click(0,0) code. Add in an override, and you can just write myButton.Click(). - This has since been implemented in NUnitAsp
