gt requires nodejs and a few modules to run. Assuming you wrote a few qunit tests in tests.js:
sudo npm install -g gtgt tests.jssome of the options
A simple example is in examples subfolder
Unit tests follow QUnit approach:
gtmodule"Basic tests";gttest"get N '='"gtoktypeof getLines === "function" "getLines is a function";gtequalgetLines0 "" "0 character";gtequalgetLines1 "=" "1 character";;
Creates unit test report (stdout only) and JS code coverage (stdout plus Lines of Code + HTML in folder cover)
gt ./examples/basic/tests ./examples/basic/exceptionTests
Sample unit test output image
Sample JS coverage output image
You can write your unit tests using coffeescript, which allows very concise code. So far, the code coverage does not include the unit test files themselves, they will be omitted from the coverage report. See examples/coffee folder.
See example examples/browser
gt provides minimal BDD support and can run Mocha/Jasmine specs that have
See spec example. You can run it using
gt --bdd spec.js command.
Creates new suite of tests with given name
You can specify additional functions to run before / after each unit tests. You can also specify a function to run once before any tests, and after all tests.
gtmodule'server tests'// setup server// clear data before each unit test// clean up after each unit test// stop server;
See module tests for more information and examples.
A very convenient feature: each method can return a promise object to tell the test engine when it is done. See example
Spawns new proces, waits for it to finish, then checks the exit code. Automatically restarts the test queue
Checking just the exit code
gtasync'run Nodejs program'gtexec'node' 'index.js' 'arg1' 'arg2' 0'expect "node index.js arg1 arg2" to exit with code 0';;
Checking the exit code and the output
gtasync'run a program'gtexec'node' 'index.js' 'arg1' 'arg2' 0if /error/teststdoutthrow 'Errors in output ' + stdout;;;
Full exec unit test
gtexeccmd 'msg';// same asgtexeccmd 0 'msg';gtexeccmd 'msg';// same asgtexeccmd 0 msg;gtexeccmd;// same asgtexeccmd 0;
Performs deep equality comparison between two objects.
gt excludes certain common paths from coverage,
speeding up the test runs: node_modules, bower_components, etc.
You can add paths to this list, for example to exclude all files
gt --no-cover vendor src/*.js tests/*.js
The option is used as case insensitive regular expression.
Author: Gleb Bahmutov © 2014
License: MIT - do anything with the code, but don't blame me if it does not work.
Spread the word: tweet, star on github, etc.
Support: if you find any problems with this module, email / tweet / open issue on Github.