Note: this was originally posted under stackoverflow, and someone sensibly downvoted it since it's really OS X specific. So I'm reposting it over here, since it's been generally helpful.
I like doing Test Driven Development (TDD), and so I would like a way for my test suite to run whenever I make a change to a source file or test file.
In addition, I'd like the results of the test to display in an ephemeral "Growl" style window in the corner of my screen, showing a green icon if all tests passed and a red icon if one or more tests fail.
I know there is such a mechanism for node.js in mocha, and for ruby environments there's guard-rspec. But how do I create one for my [fill in the blank] testing environment under OS X?
Best Answer
Under OS X, you can create a simple solution using two off-the-shelf utilities:
fswatch
andterminal-notifier
and three simple bash scripts. Here's how:download fswatch and terminal-notifier
set up project directories
My project directories are laid out as follows, but of course you can choose alternate strategies:
create three bash scripts
file: scripts/run-tests
This is a simple script that invokes your framework's tests. In this case we're running python's
unittest
, but you can customize it to suit your needs:file: scripts/growl-tests
This script invokes
run-tests
and captures stdout and stderr in log files. It then displays a growl-like message based on the results ofrun-tests
. You must customize this script to parse the results ofrun-tests
and decide whether to display a red or green icon. The example shown here parses the output of Python'sunittest
. If you use a different system, you'll need to make appropriate changes to the script.file: scripts/autorun-tests
This script invokes
growl-tests
once at startup, and then again whenever some file is modified. Under most circumstances, this file may be used verbatim without any modification.add icons to make it pretty
Put these icons in your scripts/icons directory. These will be used as the red and green icons in the Growl window.
scripts/icons/GreenBead.png:
scripts/icons/RedBead.png:
to run it
Simply open a terminal window and launch autorun-tests: