RingoJS

Module test

A test runner compliant to the CommonJS Unit Testing specification. It manages the execution of unit tests and processes test results. The runner reports the total number of failures as exit status code.

The runner treats a module like a test case. A test case defines the fixture to run multiple tests. Test cases can provide optional setUp() and tearDown() functions to initialize and destroy the fixture. The test runner will run these methods prior to / after each test. Test functions must start with a test prefix in their name, otherwise they are skipped by the runner.

The following example test case testDatabase.js starts a new test runner if executed with ringo testDatabase.js

Example

// testDatabase.js
exports.setUp = function() { ... open db connection ... }
exports.tearDown = function() { ... close db connection ... }

// Test functions start with the prefix 'test'
exports.testCreateTable = function() { ... }
exports.testInsertData = function() { ... }
exports.testTransactions = function() { ... }
exports.testDeleteTable = function() { ... }

if (require.main === module) {
  // Get a runner and run on the current module
  require("test").run(exports);
}

See

The assert module is an assertion library to write unit tests.




run (scope, name, writer)

The main runner method. This method can be called with one, two or three arguments: run(scope), run(scope, nameOfTest), run(scope, writer) or run(scope, nameOfTest, writer)

Parameters

String|Object scope

Either the path to a module containing unit tests to execute, or an object containing the exported test methods or nested scopes.

String name

Optional name of a test method to execute

Object writer

Optional writer to use for displaying the test results. Defaults to TermWriter.