Darrell Norton's Blog [MVP]

Sponsors

The Lounge

News

  • Darrell Norton pic

    MVP logo

    View Darrell Norton's profile on LinkedIn

    Currently Reading:

    weewar.com

Advertisement

Images in this post missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at imagehelp@codebetter.com
Tips and Best Practices for NUnitAsp testing

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.“

  1. 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…
  2. 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.
  3. 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).
  4. 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.
  5. 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.
  6. 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

Posted Thu, Jan 22 2004 9:34 AM by Darrell Norton
Filed under:

[Advertisement]

Comments

rjw wrote re: Tips and Best Practices for NUnitAsp testing
on Mon, Feb 7 2005 7:29 AM
erm. That is not an override, that is an overload.
Darrell wrote re: Tips and Best Practices for NUnitAsp testing
on Wed, Feb 9 2005 8:21 AM
Right, I'll update the terminology.
TrackBack wrote NunitAsp and testing controls on a page
on Fri, Feb 11 2005 7:38 AM
Kiran S wrote re: Tips and Best Practices for NUnitAsp testing
on Wed, Mar 2 2005 3:00 PM
In NUnitAsp, is there a way to work with session data, or a way to work with sequence of pages in a single session?
request wrote re: Tips and Best Practices for NUnitAsp testing
on Wed, Mar 2 2005 11:03 PM
Hi
please tell me how to write test cases for request/response as i m new to this nunitasp. i have to send a request to the server and set the headers. i couldn't find any help in NET.
hope u help me out.
Regards
request.
Darrell wrote re: Tips and Best Practices for NUnitAsp testing
on Thu, Mar 3 2005 5:52 AM
Kiran - you can just setup an NUnitAsp test that goes through all the steps and ASP.NET will keep session state on your "user".
Alex wrote re: Tips and Best Practices for NUnitAsp testing
on Tue, Mar 15 2005 5:25 PM
Have you seen SWExplorerAutomation(http://home.comcast.net/~furmana/SWIEAutomation.htm)?

SW Explorer Automation (SWEA) creates an object model (automation interface) for any Web application running in Internet Explorer. The automation interface consists of pages and controls. The page consists of controls. The following controls are supported: HtmlContent, HtmlAnchor, HtmlImage, HtmlInputButton, HtmlInputCheckBox, HtmlInputRadioButton, HtmlInputText, HtmlSelect, HtmlTextArea. The object model is defined visually by SWEA designer. The designer allows to record scripts (C# and VB) based on the defined application object model.
Girish Bharadwaj wrote ASP.NET TDD links
on Tue, May 3 2005 8:09 PM
Girish Bharadwaj wrote ASP.NET TDD links
on Tue, May 3 2005 8:11 PM
Tim Haines wrote Tips for NUnitASP
on Fri, May 6 2005 5:26 AM