37

What is the best way to test my webforms applications?

Looks like people are loving Watin, and selenium.

Glenn Slaven
  • 33,720
  • 26
  • 113
  • 165
Brian G
  • 53,704
  • 58
  • 125
  • 140
  • 1
    possible duplicate of [What is the best way to do unit testing for ASP.NET 2.0 web pages?](http://stackoverflow.com/questions/4363/what-is-the-best-way-to-do-unit-testing-for-asp-net-2-0-web-pages) – John Saunders Jun 03 '10 at 04:46
  • 1
    If this question is closed as a duplicate, the excellent answers should be merged. – John Saunders Jun 03 '10 at 04:46
  • Selenium 2 with WebForms gets a little tedious. I created some wrapper methods that make it a little easier. http://www.foliotek.com/devblog/simplifying-c-selenium-2-tests-for-asp-net-webforms/ – Narnian Oct 20 '11 at 18:36

8 Answers8

31

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. 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
  • 5,872
  • 4
  • 42
  • 51
19

UPDATE: Given WatiN has been stagnant for over a year now, I would direct anyone that needs web ui tests towards selenium, it is in continuous use & development by many contributors, and is actively used by Google.

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:

Community
  • 1
  • 1
Glenn Slaven
  • 33,720
  • 26
  • 113
  • 165
15

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
  • 12,840
  • 6
  • 48
  • 70
  • 3
    Not sure why you were downvoted so heavily, I think even many at Microsoft would agree (hence the big unit testing emphasis in MVC). Having to use a tool that opens a web browser to test code that runs server side opens up a ton of other possible failures and doesn't allow you to isolate tests to actual units of code. – Tom Lianza Dec 02 '10 at 21:06
  • 3
    I just upvoted (for the info) however downvotes make sense here because the question asks what the best way is to unit test web forms. Discussion of MVC strengths doesn't benefit that question. – John K Feb 24 '12 at 22:23
  • @TomLianza because this doesn't answer the question – MetaGuru Oct 28 '15 at 20:38
1

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

TGH
  • 38,769
  • 12
  • 102
  • 135
0

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
  • 1,646
  • 1
  • 12
  • 15
0

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 Popoff
  • 171
  • 2
  • 7
0

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.

0

I have had a great experience using Selenium. Web tests can be very fragile, but here is an article from my blog where I talk about how to make the tests less fragile. http://www.unit-testing.net/CurrentArticle/How-To-Make-Web-Tests-Less-Fragile.html

T123
  • 49
  • 4