Basic tech stuff

Programming and Linux administration

Archive for the ‘testing’ Category

Reasons for automatic tests

Posted by Daniel Brahneborg on 2007 May 22

As everybody should know by now, there are plenty of reasons for writing automatic tests. One of them, of course, being the fact that you get to see whether your application actually works, at least for some cases. That’s just a small part of the story, though.

Reason number two is design. To be able to write both small unit tests, large system tests and everything in between, the application simply must be well designed. Otherwise it will be impossible to test one thing at a time, and mock out the parts that should be faked. Knowing where to draw the lines between the modules in a system can be difficult, but by simply trying to write nice tests for them, it becomes much easier.

The third reason is refactoring, which I personally got bitten by this weekend when making a change to my RSS/Ping service, written in Ruby on Rails. In the first versions the “ping” logic was a separate program, but the users wanted it merged with the web application. So, I very carefully moved one function at a time into the classes where they belonged, and made a little button in the web interface. Despite being exactly the same code, with no uninitialized variables or anything like that, it simply refused to work.

Today I found the problem. The standalone program used a couple of require statements to import modules for RSS and Atom parsing and whatnot, things that weren’t used in the web application. This made the function fail, even though everything was technically fully correct. The standalone program worked, so tests wasn’t really necessary, I thought.

Lesson learned? Automatic tests are good, and should aim for full code coverage. This makes the programming part so much easier.

Andra bloggar om: , , .

Posted in programming, rails, testing | Leave a Comment »