Axel Ancona Esselmann
San Francisco, CA • Axel@AnconaEsselmann.com • LinkedIn • www.anconaesselmann.com
LiveUnit
A Sublime Text plug-in for continuous running of unit tests.
View a demo of LiveUnit:
Overview
When Live Unit Testing is enabled (option + command + c), the tests for a class that is being edited are continuously run in the background.
When a test fails because a class method does not exist yet, the method can be created automatically with shift + option + command + c.
Changes to test files need to be saved first to be recognized by Live Unit Testing. Changes to class files are taken into consideration instantaneously. Make sure to save your work!
You can create class-test-pairs easily with option + command + n.
Toggle back and forth between class and test file with option + command + tab.
Closing a class or test file automatically closes the respective counterpart.
Opening or switching to a class or test file automatically opens the respective counterpart.
LiveUnit currently supports PHP, python and JavaScript.
LiveUnit creates copies of your files that begin with ____liveUnitTesting_. I suggest excluding files with that beginning from being checked into repositories.
Requirements:
Unit testing with PHP requires PHPUnit.
Setting up Live Unit Testing
Live Unit Testing with PHP requires a PSR-0 compliant autoloader that gets included inside the test file.
If you don't have your own autoloader, download phpAutoloader. If you create test files with LiveUnit, your autoloader can be included automatically, if you specify the autoloader path in the settings file:
Sublime Text->Preferences->Package Settings->ClassesAndTest->Settings - User
Add the setting php_autoloader_path. Provide a relative path that starts at the namespace root directory.
Example:
You have the following folder structure:
/MyProject
/MyProject/src
/MyProject/srcTest
The namespaced name of you autoloader is:
\aae\autoload\AutoLoader
PSR-0 requires you to place the autoloader in in the folder /MyProject/src/aae/autoloader, so your setting for php_autoloader_path is:
{
"php_autoloader_path": "aae/autoload/AutoLoader.php"
}
Now, when you create new class and test files with LiveUnit, the autoloader is included in the test file.
Known issues:
When using the Live Unit Testing feature, be careful with infinite loops. Currently the only way to escape an infinite loop is to quit Sublime text. I suggest disabling Live Unit Testing whenever there is a possibility that unfinished code might be evaluated as an infinite loop.