Guard::Unity
Guard::Unity is a plugin for the ruby gem Guard that will run your Unity Test Tools tests on file changes.
Note 1: I have only tested this on mac so far, but it should also work on windows.
Note 2: I have not introduced testing for a single file on file system changes yet, but I plan to do so in the future.
Installation
Ruby
In order to run guard, you will need ruby installed on your system. I have no experience running ruby on a windows computer, but on a mac and linux, you have three choices: RVM, Rbenv (I use rbenv myself), and source.
Note: If you are using a mac, read this article first to install readline support so that notifications work. Otherwise, you may have to reinstall ruby.
Gemfile
Create a file named Gemfile (no extension) at the root of your project and add the following lines.
source 'https://rubygems.org'
gem 'guard-unity'
Notifications
If you are running mac and would like notifications, you will need readline support. See the article on guard's wiki for more help.
You will also need a gem for displaying notifications on mac. You can read about this on the wiki as well.
If you are using Mac OS X 10.8 or above, you can add the following lines to your Gemfile for system notifications.
group :development do
gem 'terminal-notifier-guard'
end
Bundle Install
When you added all your gems to your Gemfile, run bundle install in your terminal.
$ bundle install
Creating your Guardfile
Run the following command in your terminal.
$ bundle exec guard init
You will now have a file Guardfile in your project's root directory with similar contents to the following.
guard :unity do
watch(%r{^.*\.cs$})
end
The watch function within the guard :unity doblock is given a regular expression for which files to watch. The expression above will watch all .cs files and run the tests any time a .cs file is changed.
Configuration
Guard::Unity is configured to work with a basic Mac development environment without any changes. If you are using windows or have a different setup, you may need to make some configuration changes.
Here are the configuration options for Guard::Unity with their defaults.
{
test_on_start: true, # whether or not to run the tests when you start guard
project_path: Dir.pwd # the working directory for the unity project (if you supply a string, don't escape the spaces),
unity: '/Applications/Unity/Unity.app/Contents/MacOS/Unity' # the path to unity,
results_path: Dir.pwd + '/UnitTestResults.xml' # the path to the Unity Test Tools results xml file.
}
You can add the configuration variables to the Guardfile like the following example.
guard :unity, test_on_start: true, project_path: '/Users/unity/Projects/MyAwesomeGame', results_path: '/Users/unity/Projects/MyAwesomeGame/UnitTestResults.xml' do
watch(%r{^.*\.cs$})
end
Running the Tests
run bundle exec guard from the terminal and hope everything works.
$ bundle exec guard
You can press enter any time you have [1] guard(main)> displayed in your terminal to run the tests again.

