(This concept was inspired by Autotest using Watchr getting notified via Growl).
Here at appbackr, we're all about connecting app developers with backrs, who fund the app development (and make a healthy profit). To achieve this goal, we need to oil the machinery from time to time. This is one of those times.
We've recently started migrating to Yii. Yii is a MVC-based PHP framework, similar to what Rails is on Ruby. It allows us to simplify the maintenance of the appbackr marketplace and fix bugs quickly and reliably. It also decreases development time for new features, when compared to our old non-MVC site.
We want to be able to react faster, iterate in shorter cycles and produce a more stable website for app developers and backrs. Yii is relatively light weight, but provides a lot of useful features (logins, user management, ActiveRecord), thereby taking a lot of work off our shoulders. It doesn't come with the bulk other frameworks (e.g. CakePHP, Zend) do, so the learning time for the framework itself is short - giving us more time for actual development.
Yii has built-in support for PHPUnit, allowing easy unit testing. This was one of the aspects when we looked at different frameworks. We’re planning to incorporate Test Driven Development into our development process in the near future. And of course we want to cover our existing codebase with tests, so we notice when we break stuff. This will allow us to refactor without fear of breaking something, as every bug will show up as a failed test.
Now you could run the tests manually after each change by typing 'phpunit <your test folder>', but we were looking for something a little more comfortable. We want to decrease the transactional cost of running the tests as much as possible to make the lives of our engineers more pleasant. Making testing easy is the only way the engineers will run the tests frequently.
The goal was to have a solution that you don’t have to care about at all and that gives you, as an engineer, instant feedback on your code changes.
Enter Watchr. Watchr is a ruby tool that monitors a specified list of files for change. It allows you to execute scripts on defined changes in files. In simple terms: As soon as you save changes to your code, Watchr will run your test suite and inform you if the tests ran through. Automatically, without you ever having to switch to the terminal, type anything or even click a button.
For better visibility and instant feedback, I looked for something simple that gives engineers instant feedback about the status of their tests. Scanning the terminal for F (Failure) takes too long and is tiring. We found Growl, the omnipresent Mac OS X notification tool. Dropbox and Adium are using Growl. Almost every app on OS X uses Growl for notifications. You know, these little boxes?
All tests succeeded. Good times.
By combining PHPUnit, Watchr and Growl, we get super slick auto testing for our local dev environments. It keeps us notified, while coding, if we break stuff.
As soon as we save any changes on the source, Watchr starts our PHPUnit test suite. About two seconds later, like magic, the little Growl notification in the upper right informs us if our tests succeeded. If they did, it's green. If they failed, it's red.
Slartibartfas could not be found. Now we need to fix that.
Setting up all this is quite easy. Just download and install PHPUnit, Watchr and growlnotify. For simplicity's sake, I've put a copy of my watchr.rb script on github.
Here’s the gist of it:
I’m looking forward to hearing your feedback. There is a lot of room for improvements, so feel free to leave your thoughts. If you know similar notification tools for Ubuntu and Windows, please let us know in the comments.
Happy coding!