Catherine Gracey

Living Life, One Misadventure At A Time.

Testing a New Approach

on August 17, 2016

Last month I had my first in-person interview for a programming job. I had almost a week to prepare for it, so I decided to spend the time looking into a few of the tools and JavaScript libraries that I’ve always meant to look into but have never made the time for. It was an intense few days where I picked up a lot of new skills and mentally kicked myself for not doing it earlier.

My favourite new skill is testing. I worked through a course on Mocha.js and Chai.js. Mocha is a test framework and Chai is an assertion library, and together they tie in very nicely with behavioural driven development. In English, that means that when I plan to write a section of my program, I can tell the tests what it should do and then the tests will tell me if my program succeeds or not. This might sound like doing double the coding work for no additional functionality, and in a way it is, but it means that every time I want to test my code I can just type a single command and the program will check itself. If I write my tests sensibly, it means that I can make changes without worrying about breaking something else that I don’t realise is connected to the part of the program I’m working on. If something does break, my tests will tell me what and where it is broken, so I don’t have to spend hours trying to hunt down the problem. It’s pretty neat.

Adding tests to my sandbox websites was simple. Writing the test and the code to go with it was straight forward when I wrote the tests first. My structure just worked naturally, and I was thrilled to see that test driven development was considerably faster for me than manually testing as I went, even with the additional coding required.

After a few weeks of practicing in the sandbox websites, it was time to try adding tests to This was a very daunting proposition, because I have spent months coding this particular project. It is the most complex thing I have ever attempted, and in the process of writing it I’ve come up with quite a few little work-arounds that I’m not particularly keen to revisit. I did not structure the site with testing in mind, which is painfully obvious in almost every file that I open.

I decided to begin small, with the library module. My first tests just checked if the test suite could access the library files and if the correct languages were present. I expanded the tests to check if each language had entries in each genre that I plan to include. Within the first day I had already written hundreds of tests and refactored my code considerably. As I wrote each new test, I was conscious that these tests would have to handle future developments to the site. This is where I am learning how to scale.

Nine days of intense coding later, and Mocha reports that I have written well over 1000 tests. To come that far has meant restructuring most of the website, and I have barely started drilling into specific modules. So much has been broken down, modularised, and reassembled in a way that is much more predictable. Theories and methods that I have encountered over the past year and never found a use for seem vital now. Business level decisions that I have struggled with for years suddenly became obvious in the test environment. I stopped asking “how can I keep track of this?” and started asking “how can the computer track this for me?” Most importantly, I can now see how other people could work on the project without disrupting my own work. I don’t have to keep everything in my head any more, and it’s giving me the space to finally think again.

I didn’t end up getting that programming job, but I’m not disappointed; there are still a few questions the interviewer asked that I didn’t have good answers for, and if they turn out to be as helpful as testing has been, I will be too busy learning to work for anyone else for quite some time.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: