Tag-arkiv: tdd

Reclaim control of your application with Cucumber

As I’ve written earlier(danish), I’ve arrived rather late to the test-driven development-train. As a result I have a large application, developed in Rails, but without utilizing the test framework. Granted I have lately added some unit-tests, but in the whole, I would deem the application uncovered by tests.

Such a beast is difficult to handle. To upgrade it to support the latest Rails version (2.3.5 in this time of writing) is like jumping of a plane and hope to catch a floating parachute on your way down. On the other hand, writing unit-tests and functional tests to cover all current functionality is a huge task, that is discouraging simply by its presence. To put it short: The application has grown beyond my control.

So how to tackle this situation? I want the entire application (or most of at least) covered by test, but I will not be able to spare the next 3 months doing nothing but writing unit and functional tests.

Enter Cucumber.

With Cucumber I am able to create happy paths for all the use cases in my application. I know how each area of the application is supposed to be used, and by outlining these uses in Cucumber features and scenarios, I get a basic coverage of all functionality.

This is a very top-down approach. I don’t get to test each small functionality separately. And even the Cucumber guys encourage coders to write more than just happy paths (adding also scenarios that are supposed to test for error messages). But at least, if something breaks, I will know about it. So when I change something in my application, I run all my cucumber features. If one of the scenarios fail, I can now focus on writing more detailed tests for this particular part of the application.

A big thanks to Aslak Hellesøy and friends for helping me reclaim control of my application!

Bookmark and Share

Test test og atter test

Jeg er nu endelig kommet på den rette vej med TDD. Jeg må jo indrømme, at TDD for mig indtil nu har været “kode først, tests bagefter”, men jeg så forleden lige pludselig “lyset”. Det har også kun taget 2¾ år med Rails at nå dertil… ;-)

Hvad gjorde så udslaget for mig? Jo det var faktisk, da jeg læste denne blog http://code.isdangero.us/posts/My-test-driven-Ruby-setup

Jeg kunne godt lide syntaksen i Shoulda. Men det var især Machinist og den lette måde at lave test-data på, som gav mig en “aha-oplevelse”. Fixtures er besværlige at lave, og det er nemt at knække eksisterende tests, når man tilføjer flere tests. Machinist ændrer på alt det, og det gik pludselig op for mig, at det netop var dét, der var bremsen for min omvenden.

Men for pokker hvor er der pludselig mange forskellige frameworks/ libraries til TDD/BDD. Det er jo nærmest en jungle. Det er sjovt, at hvor de fleste bare accepterer ActiveRecord og de øvrige konventioner i Rails, så bruger rigtig mange tilsyneladende alt muligt andet end Rails’ egent test-suite.

Hvilken kombi bruger i og hvorfor? Hvor nemt har i ved at teste først og kode bagefter? Jeg er gammel i gårde, og jeg må indrømme, at det er en af de steder, hvor jeg har svært ved at ændre gamle vaner.

- Carsten

Bookmark and Share