views:

1741

answers:

9

What is the best way to Unit test my webforms applications?

Looks like people are loving Watin, and selenium.

+12  A: 

WatiN is the best that I've found. It integrates into Visual Studio unit testing or nunit & you can do pretty much anything you need in the browser (click links, submit forms, look for text/images, etc.)

See the following questions for similar answers:

Glenn Slaven
I have to learn to type faster...good suggestion
JustinD
Isn't that integration/acceptance testing as it's running in the browser?
jbloomer
+1  A: 

I would use a tool like WaitIn:

" WatiN is Web Application Testing in .NET, and this Test Recorder will generate chunks of source for you by recording your clicks in an embedded IE browser" (from Scott Hanselman's blog - which I found thanks to another post on StackOverflow

WaitIn website

JustinD
A: 

That's the biggest shortcoming of Webforms -- it's, for all practical reasons, untestable in terms of unit testing of testing controllers, etc.

That is one of the major advantages of the MVC framework.

Ian P
+1  A: 

Selenium - I love it!

Svet
Do you use this for Regression testing as well?
Brian G
A: 

I'd go with WATIR (Web Application Testing in Ruby) - http://wtr.rubyforge.org/. We (Acsys Interactive) have been using for about a year and the tool is great.

I developed a simple wrapper in .NET so that I can execute my WATIR scripts from Unit tests. The framework is incredible and you have entire Ruby power behind you. There's support for Firefox & Safari (FireWatir project).

It's very similar to WATIN (in fact I think WATIN was inspired by WATIR) but I find that WATIR community is much larger than WATIN one.

There're test recorders out there that you can use and tons of tutorials.

It's really your choice. If you feel like the tests need to be in .NET and you don't want to support any other language then your choice is WATIN. On the other hand, if you want to try a fun and quite powerful scripting language (that's what Ruby is) then go for WATIR.

Question to WATIN guys, does it support FireFox/Safari?

Gleb Popov
Yes, it supports FireFox
Vadi
A: 

Here is a review of Watin,Watir and Selenium http://adamesterline.com/2007/04/23/watin-watir-and-selenium-reviewed/

Apparently Selenium worked quite slow for the tester but if you'll notice, as one of the comments points out, that this is only the case due to its support of multiple browsers.

However there is a CTP (Community Technology Preview) release of WatiN which offers support for both Internet Explorer and FireFox automation.

Stephen lacy
+4  A: 

Just wondering, why would you call WatiN a unit testing tool? Last time I checked, it ran integration tests.

The best way would be to move all code that doesn't depend on HttpContext to a separate assembly and run unit tests as usual. The rest can be tested with Ivonna (sm-art.biz/Ivonna.aspx). She doesn't test the client behavior, that's where WatiN can be helpful; however, if you want to test your pages or controls in isolation, she's your only choice.

ulu
This should be the accepted answer. The accepted answer is wrong.
youwhut
A: 

I tend to favor the approach of separating the buisness logic out of the UI code. Here's an article that describes a unit test friendly pattern (Model-View-Presenter)

http://www.unit-testing.net/CurrentArticle/How-To-Use-Model-View-Presenter-With-AspNet-WebForms.html