Class o2.Unit


static class o2.Unit

A "unit test" runner.

Runs UnitTests.

Defined in unit.core

Function Summary
static add (String description, Object testMeta)

Creates a test suite parsing the testMeta, and adds it to the test queue.

Usage example:

 o2.Unit.add('some method SHOULD meet a requirement', {
      count: 1,
      test : function() {
          var me = this;
          o2.Unit.assert(me, false, 'I pass.');
      }
 });
 
static assert (o2.UnitTest unitTest, Expression expression, String message)

Asserts whether the given expression evaluates to true or not.

Usage example:

 o2.Unit.assert(me, condition, 'condition is true');
 
static assertEqual (o2.UnitTest unitTest, Object currentValue, Object expectedValue, String message)

Asserts whether two values are equal.

Usage example:

 o2.Unit.assertEqual(me, 10, '10', '10 is 10');
 
static assertNotEqual (o2.UnitTest unitTest, Object currentValue, Object expectedValue, String message)

Asserts whether two values are NOT equal.

Usage example:

 o2.Unit.assertNotEqual(me, 10, '11', '10 is not 11');
 
static assertStrictEqual (o2.UnitTest unitTest, Object currentValue, Object expectedValue, String message)

Asserts whether two values are strictly equal (by value and type).

Usage example:

 o2.Unit.assertStrictEqual(me, 10, 10, '10 is 10');
 
static assertStrictNotEqual (o2.UnitTest unitTest, Object currentValue, Object expectedValue, String message)

Asserts whether two values are strictly NOT equal (by value and type).

Usage example:

 o2.Unit.assertStrictNotEqual(me, 10, '10', '10 is not 10');
 

Gets the total number of failed assertions so far.

Usage example:

 var totalFail = o2.Unit.getGlobalFailureCount();
 

Gets the total number of successful assertions so far.

Usage example:

 var totalSuccess = o2.Unit.getGlobalSuccessCount();
 
static isRunning()

Checks whether the current test suite is still running.

Usage example:

 var isActive = o2.Unit.isRunning();
 
static log()

Usage example:

 o2.Unit.log('hello world');
 

Logs the message.

An alias to Debugger.log.

static run (Function globalCompletionCallback)

Asynchronously runs all of the registered UnitTests, one after another.

Usage example:

 o2.Unit.run(function() {
      // Completed.
 });
 

Function Details

function add

static add(String description, Object testMeta)

Creates a test suite parsing the testMeta, and adds it to the test queue.

Usage example:

 o2.Unit.add('some method SHOULD meet a requirement', {
      count: 1,
      test : function() {
          var me = this;
          o2.Unit.assert(me, false, 'I pass.');
      }
 });
 
Parameters:
description - the description of the test.
testMeta - test meta data in the form {count: [number], test: [callback]}, where count is the total number of assertions in the test suite, and test is the actual test suite Function.

function assert

static assert(o2.UnitTest unitTest, Expression expression, String message)

Asserts whether the given expression evaluates to true or not.

Usage example:

 o2.Unit.assert(me, condition, 'condition is true');
 
Parameters:
unitTest - the current active unit test.
expression - the expression to evaluate.
message - the associated message.

function assertEqual

static assertEqual(o2.UnitTest unitTest, Object currentValue, Object expectedValue, String message)

Asserts whether two values are equal.

Usage example:

 o2.Unit.assertEqual(me, 10, '10', '10 is 10');
 
Parameters:
unitTest - the current active unit test.
currentValue - the current value to assert.
expectedValue - the expected value to check against.
message - the associated message.

function assertNotEqual

static assertNotEqual(o2.UnitTest unitTest, Object currentValue, Object expectedValue, String message)

Asserts whether two values are NOT equal.

Usage example:

 o2.Unit.assertNotEqual(me, 10, '11', '10 is not 11');
 
Parameters:
unitTest - the current active unit test.
currentValue - the current value to assert.
expectedValue - the expected value to check against.
message - the associated message.

function assertStrictEqual

static assertStrictEqual(o2.UnitTest unitTest, Object currentValue, Object expectedValue, String message)

Asserts whether two values are strictly equal (by value and type).

Usage example:

 o2.Unit.assertStrictEqual(me, 10, 10, '10 is 10');
 
Parameters:
unitTest - the current active unit test.
currentValue - the current value to assert.
expectedValue - the expected value to check against.
message - the associated message.

function assertStrictNotEqual

static assertStrictNotEqual(o2.UnitTest unitTest, Object currentValue, Object expectedValue, String message)

Asserts whether two values are strictly NOT equal (by value and type).

Usage example:

 o2.Unit.assertStrictNotEqual(me, 10, '10', '10 is not 10');
 
Parameters:
unitTest - the current active unit test.
currentValue - the current value to assert.
expectedValue - the expected value to check against.
message - the associated message.

function getGlobalFailureCount

static getGlobalFailureCount()

Gets the total number of failed assertions so far.

Usage example:

 var totalFail = o2.Unit.getGlobalFailureCount();
 
Returns:
the total number of failed assertions.

function getGlobalSuccessCount

static getGlobalSuccessCount()

Gets the total number of successful assertions so far.

Usage example:

 var totalSuccess = o2.Unit.getGlobalSuccessCount();
 
Returns:
the total number of successful assertions.

function isRunning

static isRunning()

Checks whether the current test suite is still running.

Usage example:

 var isActive = o2.Unit.isRunning();
 
Returns:
true if the current test suite is still runing; false otherwise.

function log

static log()

Usage example:

 o2.Unit.log('hello world');
 

Logs the message.

An alias to Debugger.log.

See also:

function run

static run(Function globalCompletionCallback)

Asynchronously runs all of the registered UnitTests, one after another.

Usage example:

 o2.Unit.run(function() {
      // Completed.
 });
 
Parameters:
globalCompletionCallback - (Optional) this callback will be run with o2.Unit as a parameter passed to it.