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
This entry was posted in .NET. Bookmark the permalink. Follow any comments here with the RSS feed for this post.

6 Responses to Tips and Best Practices for NUnitAsp testing

  1. Alex says:

    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.

  2. Darrell says:

    Kiran – you can just setup an NUnitAsp test that goes through all the steps and ASP.NET will keep session state on your "user".

  3. request says:

    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.

  4. Kiran S says:

    In NUnitAsp, is there a way to work with session data, or a way to work with sequence of pages in a single session?

  5. Darrell says:

    Right, I’ll update the terminology.

  6. rjw says:

    erm. That is not an override, that is an overload.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>