https://github.com/matsadler/mini-unit
xUnit style test cases, suites, and runner for Node's assert module.
https://github.com/matsadler/mini-unit
Last synced: 3 months ago
JSON representation
xUnit style test cases, suites, and runner for Node's assert module.
- Host: GitHub
- URL: https://github.com/matsadler/mini-unit
- Owner: matsadler
- Created: 2012-02-12T22:48:58.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2012-02-12T22:52:53.000Z (over 13 years ago)
- Last Synced: 2025-02-16T21:08:02.310Z (3 months ago)
- Language: JavaScript
- Homepage:
- Size: 85.9 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# MiniUnit
xUnit style test cases, suites, and runner for Node's assert module. Inspired by
Ruby's MiniTest::Unit.MiniUnit is only intended to help you structure your tests, it is expected
you'll be using it with the [Node.js assert module][assert] for assertions.[assert]: http://nodejs.org/docs/latest/api/assert.html
## Usage
// require MiniUnit and Node's assert module
var MiniUnit = require("mini-unit");
var assert = require("assert");
// require the module under test
var MyModule = require("./../lib/my-module");
// create and name a test case
var tc = new MiniUnit.TestCase("MyModule");
// run before each test
tc.setup = function () {
this.adder = new MyModule.adder();
};
// run after each test
tc.teardown = function () {
this.adder.reset();
};
// test methods must be named 'test' followed by at least one character.
tc.testAddition = function () {
var a = 2,
b = 2,
result,
result = this.adder.add(a, b)
assert.equal(result, 4);
};
// if the file being run is the current file, then run the tests, otherwise
// export the test case
if (require.main === module) {
MiniUnit.run(tc);
} else {
module.exports = tc;
}### Running a suite of test cases
var MiniUnit = require("mini-unit");
var testCases = [
"./foo",
"./bar"
].map(function (path) {
return require(path);
});
MiniUnit.runSuit(testCases);