betabug... Sascha Welter

home english | home deutsch | Site Map | Sascha | Kontakt | Pro | Weblog | Wiki

25 December 2005

Unit Testing the Witch

Split and test
 


After the last few weeks at work, where we worked hard and fast to finish part of a project, with the holidays and free time at my hand, I had nothing better to do than to code at home... I finally got around to writing some unit tests for the RewriteRule witch (a script to generate apache RewriteRules for Zope). The code of the witch stayed the same as far as actual output is concerned.

There is one difference to the code, something that the last few weeks working with ZopeTestCase unit tests had taught me: Split up the code on the boundary that affects the web browser. The witch consists mainly of one simple method. It picks up the parameters from the http request, shows the form (if no input given), or shows the form together with the result (if form input was provided).

Since unit testing form input is complicated, what I ususally do is split request processing and actual logic work. So there is now a public method to handle the request, and a private method to do calculation. And the private method is written in a way that it can be tested easily, without having to rely on form handling. That makes testing at least the important stuff possible. I can make changes to the code and be sure that the most basic variants of output stay the same.


Posted by betabug at 23:15 | Comments (0) | Trackbacks (0)
ch athens
Life in Athens (Greece) for a foreigner from the other side of the mountains. And with an interest in digital life and the feeling of change in a big city. Multilingual English - German - Greek.
Main blog page
Recent Entries
Best of
Some of the most sought after posts, judging from access logs and search engine queries.

Apple & Macintosh:
Security & Privacy:
Misc technical:
Athens for tourists and visitors:
Life in general:
<< Το πιο πρόστυχο σκράμπλ (ever) | Main | Xmas Break Program >>
Comments
There are no comments.
Trackbacks
You can trackback to: http://betabug.ch/blogs/ch-athens/260/tbping
There are no trackbacks.
Leave a comment