views:

125

answers:

4

I've been working for a while with .net unit testing and stuff. Now I need to create tests for ascx and ascx.cs pages (but it aspx and aspx.cs references might also help). I'm not very familiar with webtests. Can anyone give hints or references that might help (tutorials, blog posts about best practices, etc.)?

It can be references about tests using VS2008 tools or coding the tests using a text editor.

A: 

Hello,

You can take a look to this article at MSDN

Sebastian
I'm having a look at it
Samuel Carrijo
A: 

Grab a copy of Fiddler2. When run it will "record" your session with the ASP.NET server (requests and responses - also done by Visual Studio when "recording" a new web test). You can then select the requests and save them as a visual studion web test.

The rest is all about understanding how ASP.NET creates and uses Requests and responses to control the application.

Turn your web tests into coded webtests and search microsoft for details on each object the webtest uses for extra credit.

Nat
A: 

I recommend not to test "ascx and ascx.cs" but to test the UI that's displayed to user and to test services/repositories/modules (if you are using some good modular architecture and aren't writing all code in codebehind pages). To test the UI you can use Selenium RC. There are a lot of usage samples for it:
http://www.lostechies.com/blogs/agilecruz/archive/2009/02/10/how-to-configure-selenium-rc-for-use-in-c-nunit-tests.aspx
http://thetestingblog.com/2009/09/10/selenium-rc-in-c-using-nunit-an-end-to-end-example/
http://www.stevetrefethen.com/blog/AutomatedtestingofASPNETwebapplicationsusingSelenium.aspx
http://codebetter.com/blogs/jeremy.miller/archive/2006/05/14/144666.aspx
And also there is a special .net toolkit for it.

zihotki
+1  A: 

First, lets take a step back and get clear on what you're trying to accomplish by testing the UI page and controls. Are you just trying to see that your application data can be rendered in a page/control?

In my experience it takes an order of magnitude more work to test the web UI layer than it does to test your nicely separated business and data layers. If you design your application following a solid MVC pattern you can easily automate testing of the Controller and Model layers which include all the data access and business rules. This should be done using MSTest, NUnit, or XUnit, etc.

Your web presentation layer (i.e. web .ASPX pages and .ASCX user controls) should just be hooked in to the same business logic via the controllers...which will have been already tested.

If you believe in the 80/20 rule, in this case it means 80% of your application will be tested with 20% of your effort. Going the extra mile to automate testing of individual pages and controls is overkill for most projects; instead, I recommend just creating a load test in Visual Studio, recording basic use cases such as logging in, loading a few pages and interacting with a few page controls.

Run this load test to verify the application is behaving correctly in your development and test environments, and once in production you'll need actual users to verify that everything is working correctly anyway.

To see documentation on the ASP.NET MVC2 framework click here

To see a general description of the MVC pattern click here

Winger