Categories
programming

(Again) Why Test?

When whipping out the Josephus game, I used Jasmine to write the tests… er.. spec for anticipating the behaviour of the code. Among the many reasons I use a “test-driven methodology” (even in the smallest of projects) is that I like to (nay, NEED to) keep a close eye on the strategic direction of the code while I’m minutely engaged in the technical direction. And a picture like this is so easy to read:

Strategy

Categories
programming Technology

Javascript Jasmine

If you know me (or have worked with me) then there’s one thing you’ll be quickly become aware of with regards my coding behaviour: tests. I love tests. More importantly, I love meaningful, passing tests that validate my sanity and check my logic in critical areas.

And Javascript is no exception. I’ve run with jsUnit for quite some time now (because it just worked). Subsequently though, I got my hands dirty with it’s upgraded re-written cousin: Jasmine. There’s not much I can say about getting going with Jasmine since, to be fair, it really is so simple and well documented on the site already, needless to say:

1. Don’t Panic
This useful bit of instruction should be mandatory on every new piece of technology and before you take on any new learning. Don’t you feel better already?

2. Download the archive for standalone javascript projects
The primary folder of interest is the aptly-named lib folder which is, well, the core library.

3. Prepare a test runner
You need a test runner (test harness, if you like) for actually running the tests and a demo has been provided for you in the form of the included SpecRunner.html

4. Write tests
The included ‘src’ folder is the sample functionality under test. This is usually your own code. The ‘spec’ folder contains sample test code. I say -test- but when you start moving into proving behaviours, -test- seems such a dry word, and so the word -specification- is born, but that may sound too technical and daunting (until you become used to it). The two are, for all intensive purposes the same to the newly initiated, but quite different once you start grokking the subtle differences.

5. Have fun
Now go get on with doing something awesome.