Bunoon: JUST | Manual | Additional Functions

Below is a list of the additional functions that can be called within the tests to perform various tasks. Some of the functions listed can be called from outside a TestCase() scope, which have additional examples.

Handles writing a new string line to the report (using the built-in private function) if we are reporting everything.

The main arguments for this function are as follows:

  • string [String] - The text that should be displayed in the line (prints a new line if an empty string is supplied).
  • cssClass [String] - The CSS class that should be used for the string (defaults to "ReportTextClass" setting).

Below is an example of how to use this function:

var test = new $T.Class.New( {

_inherit_: new $J.TestCase(),


test: function () {

this.Assert.StrictEqual( 1, 1 );

this.Print( "This is an example of a message being printed after an assert test." );

}

} );

Allows sleeping (pausing) a specific number of milliseconds before continuing on with the next task.

The main arguments for this function are as follows:

  • milliSeconds [Number] - The number of millisecond that we should sleep for.

The return value for this function is as follows:

  • [Boolean] - A boolean of true/false to indicate if the sleep timer was run.

Below is an example of how to use this function:

var test = new $T.Class.New( {

_inherit_: new $J.TestCase(),


test: function () {

this.Assert.StrictEqual( 1, 1 );

this.Sleep( 100 );

}

} );

Returns the ID that has been assigned to this TestCase() instance.

The return value for this function is as follows:

  • [Object] - The ID that has been assigned to this TestCase() instance (defaults to null).

Below is an example of how to use this function:

var test = new $T.Class.New( {

_inherit_: new $J.TestCase(),


test: function () {

this.Assert.StrictEqual( 1, 1 );

}

} );


var id = oTesting.GetID();

Adds a new test to the TestCase() class.

The main arguments for this function are as follows:

  • testName [String] - The name that should be used for the test.
  • functionReference [Object] - The function that should be assigned to the test.

The return value for this function is as follows:

  • [Boolean] - A boolean of true/false to indicate if the test has been added.

Below is an example of how to use this function within a class:

var test = new $T.Class.New( {

_inherit_: new $J.TestCase(),


test1: function () {

this.Assert.StrictEqual( 1, 1 );

this.AddTest( "test2", function () {

this.Assert.StrictEqual( 2, 2 );

} );

}

} );

Below is an example of how to use this function when building up a TestCase():

var test = new $J.TestCase();


oTesting.AddTest( "test1", function () {

oTesting.Assert.StrictEqual( 1, 1 );

} );


oTesting.Run( { ReportToConsole: true, ReportEverything: true } );

Removes a test from the TestCase() class (has no effect on the summary or results if the test has already been run).

The main arguments for this function are as follows:

  • testName [String] - The name of the test to remove.

The return value for this function is as follows:

  • [Boolean] - A boolean of true/false to indicate if the test has been removed.

Below is an example of how to use this function:

var test = new $T.Class.New( {

_inherit_: new $J.TestCase(),


test1: function () {

this.Assert.StrictEqual( 1, 1 );

this.RemoveTest( "test2" );

},


test2: function () {

this.Assert.StrictEqual( 2, 2 );

}

} );

Below is an example of how to use this function when building up a TestCase():

var test = new $J.TestCase();


oTesting.AddTest( "test1", function () {

oTesting.Assert.StrictEqual( 1, 1 );

} );


oTesting.RemoveTest( "test1" );


oTesting.Run( { ReportToConsole: true, ReportEverything: true } );

Forces the tests to stop running and shows the reason why at the bottom of the report (the overall summary is ignored).

The main arguments for this function are as follows:

  • reason [String] - The reason why the tests have been stopped.

The return value for this function is as follows:

  • [Boolean] - A boolean of true/false to indicate if the tests have been stopped.

Below is an example of how to use this function:

var test = new $T.Class.New( {

_inherit_: new $J.TestCase(),


test: function () {

this.Assert.StrictEqual( 1, 2 );

this.Stop( "The tests have been stopped because this test failed." );

}

} );

Determines if a test exists within the TestCase() class.

The main arguments for this function are as follows:

  • testName [String] - The name of the test to check.

The return value for this function is as follows:

  • [Boolean] - A boolean of true/false to indicate if the test has been removed.

Below is an example of how to use this function:

var test = new $T.Class.New( {

_inherit_: new $J.TestCase(),


test1: function () {

this.Assert.StrictEqual( 1, 1 );

var exists = this.Exists( "test2" );

}

} );

Below is an example of how to use this function when building up a TestCase():

var test = new $J.TestCase();


oTesting.AddTest( "test1", function () {

oTesting.Assert.StrictEqual( 1, 1 );

} );


var exists = oTesting.Exists( "test2" );


oTesting.Run( { ReportToConsole: true, ReportEverything: true } );

Returns the current duration of the tests that are running.

The return value for this function is as follows:

  • [Number] - A number containing the current duration of the tests.

Below is an example of how to use this function:

var test = new $T.Class.New( {

_inherit_: new $J.TestCase(),


test: function () {

this.Assert.StrictEqual( 1, 2 );

var duration = this.Duration();

}

} );

Returns a boolean stating if any tests are currently being run.

The return value for this function is as follows:

  • [Boolean] - A boolean of true/false to indicate if tests are being run.

Below is an example of how to use this function:

var value = $J.IsRunning();

Forces the report to be cleared (be careful when using this function, as it will clear the console as well, making it harder to see failures).

The return value for this function is as follows:

  • [Boolean] - A boolean of true/false to indicate if the report has been cleared.

Below is an example of how to use this function:

var test = new $T.Class.New( {

_inherit_: new $J.TestCase(),


test: function () {

this.Assert.StrictEqual( 1, 2 );

var cleared = this.Clear();

}

} );

Determines if a test (by name) has been run.

The main arguments for this function are as follows:

  • testName [String] - The name of the test to check.

The return value for this function is as follows:

  • [Boolean] - A boolean of true/false to indicate if the test has been run.

Below is an example of how to use this function:

var test = new $T.Class.New( {

_inherit_: new $J.TestCase(),


test1: function () {

this.Assert.StrictEqual( 1, 1 );

},


test2: function () {

this.Assert.StrictEqual( 1, 2 );

var run = this.HasTestRun( "test1" );

}

} );