CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

Darrell Norton's Blog [MVP]

Fill in description here...

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

Published Jan 22 2004, 09:34 AM by darrell
Filed under:

Comments

Darrell said:

Right, I'll update the terminology.
# February 9, 2005 8:21 AM

TrackBack said:

# February 11, 2005 7:38 AM

Kiran S said:

In NUnitAsp, is there a way to work with session data, or a way to work with sequence of pages in a single session?
# March 2, 2005 3:00 PM

request said:

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.
# March 2, 2005 11:03 PM

Darrell said:

Kiran - you can just setup an NUnitAsp test that goes through all the steps and ASP.NET will keep session state on your "user".
# March 3, 2005 5:52 AM

Alex said:

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.
# March 15, 2005 5:25 PM

Girish Bharadwaj said:

# May 3, 2005 8:09 PM

Girish Bharadwaj said:

# May 3, 2005 8:11 PM

Tim Haines said:

# May 6, 2005 5:26 AM
Check out Devlicio.us!