Closure Testing
nclosure supports testing using Closure's 'goog.testing.jsunit' test tools.
To set up a unit test simply create a test file like:
#!/usr/local/bin/node
// You can now run the test just by executing this file
require('nclosure').nclosure();
goog.require('goog.testing.jsunit');
// Import the code you are testing (may need an additionalDeps defined)
goog.require('nclosure.examples.simple.Example');
// Any testXXX function are auto-discovered and run
var testFunction1 = function() {
assertNotEquals(typeof(example_), 'undefined');
};
// Also auto discovered
function testFunction2() {
assertTrue(false);
}
If the tests are not in the same directory as your code you will have to
ensure that the deps.js file of the code you are testing
is declared in the closure.json file of the tests directory or passed in to the
call to nclosure(); like:
require('nclosure').nclosure({additionalDeps:['/pathToDeps/deps.js']});
To run a single test just execute:
./testSourceFile.js <optionalTestName>
To run all tests (files with the word test or suite in them) in a single directory (recursive) run the following command:
nctest <dirname>
The testing framework also supports test suite files. If you want to have a test suite simply have an array var named suite with the files to test (relative to the suite file). I.e.
// Run all the tests inside the '../examples/simple/' directory
// This array can be directories or specific test (or other suite)
// files
var suite = ['../examples/simple/'];