Friday, September 28, 2007

Web application unit testing

How to test applications on .Net

The thing that popped into my mind is "User Interface testing is not stable". Period.

Any time I tried to test user interface, everything ended up in recycle bin next week, if not next day. If you want to tage huge advantage of unit testing your code, you must write it clean and separated. That's true both for web and desktop applications.

If you ask what is clean and separated code I would describe it like this: your code must be written in as small chunks as possible. Your functions should only one single thing, your classess should have only one responsibility, your namespaces should be grouped by behaviour.

It's like in orchestra - if you have a violin, a guitar and a maestro, then you have three responsibilities - play violion, play guitar and act as a maestro.

If you happen to write a Web application, do not follow blind examples of putting together your data loading, decision and presentation logic into one single code-behind (or whatever) class. It's allways the same three letters - Model / View / Controller - MVC.

It's as important to separate M from C, as to P from M and C. Your presentation can NEVER be together with your controllers. Clean separation is both a prerequisite for unit testing, and a result of it.

Web unit testing could check your model and controller classes. hammet, maintainer of Castle Project also tests ViewComponents.

As for unit testing tools, one of the more popular are watin and Selenium. You also check my presentation about selenium: pdf format odp format

No comments: