Test driving Brackets
Jan 2, 2013 20:01 · 230 words · 2 minute read
I got test infected a number of years ago, so it was perfectly natural for me to want to test-drive changes to Brackets, now that I’m back into writing code. In fact, I had a perfect bug to work on for test-driven development: improving the QuickOpen heuristics. This code needs to be able to return proper matches with reasonable scores, something that is very easily tested.
When I started working on this bug, QuickOpen did not have any tests. Additionally, running the tests required reaching for the mouse every single time. That’s more irritating than you might expect if you’ve never done test driven development. So, I created a Brackets extension called TestQuickly that lets me run tests appropriate for the current file with a quick keystroke. I made the QuickOpen.js and QuickOpen-test.js files both run the QuickOpen test suite when I hit that key with the file open.
After that bit of setup, I had to start writing tests for the QuickOpen (there weren’t any tests already) and I had to learn Jasmine’s style as well. Writing the tests proved to be straightforward indeed. Alas, improving the QuickOpen heuristics was not quite so easy, but the new results are much better. You can take a look at the code I ended up with in this commit.
I made a screencast with a quick demo of the workflow I used: