Class o2.Unit
static
class
o2.Unit
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.');
}
});
Asserts whether the given expression evaluates to
true or not.
Usage example:
o2.Unit.assert(me, condition, 'condition is true');
Asserts whether two values are equal.
Usage example:
o2.Unit.assertEqual(me, 10, '10', '10 is 10');
Asserts whether two values are NOT equal.
Usage example:
o2.Unit.assertNotEqual(me, 10, '11', '10 is not 11');
Asserts whether two values are strictly equal (by value and type).
Usage example:
o2.Unit.assertStrictEqual(me, 10, 10, '10 is 10');
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();
Checks whether the current test suite is still running.
Usage example:
var isActive = o2.Unit.isRunning();
Usage example:
o2.Unit.log('hello world');
Logs the message.
An alias to Debugger.log.
Asynchronously runs all of the registered
UnitTests, one after another.
Usage example:
o2.Unit.run(function() {
// Completed.
});
Function Details
function add
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.');
}
});
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');
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');
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');
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');
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');
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();
function getGlobalSuccessCount
static
getGlobalSuccessCount()
Gets the total number of successful assertions so far.
Usage example:
var totalSuccess = o2.Unit.getGlobalSuccessCount();
function isRunning
static
isRunning()
Checks whether the current test suite is still running.
Usage example:
var isActive = o2.Unit.isRunning();
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.
function run
static
run(Function
globalCompletionCallback)
Asynchronously runs all of the registered
UnitTests, one after another.
Usage example:
o2.Unit.run(function() {
// Completed.
});
globalCompletionCallback
- (Optional) this callback
will be run with o2.Unit as a parameter passed to it.
A "unit test" runner.
Runs
UnitTests.