Class: CoreTest.Plan

A test plan contains a set of functions that will be executed in order. The results will be recorded into a results hash as well as calling a delegate.

When you define tests and modules, you are adding to the active test plan. The test plan is then run when the page has finished loading.

Normally you will not need to work with a test plan directly, though if you are writing a test runner application that needs to monitor test progress you may write a delegate to talk to the test plan.

The CoreTest.Plan.fn hash contains functions that will be made global via wrapper methods. The methods must accept a Plan object as their first parameter.

Results

The results hash contains a summary of the results of running the test plan. It includes the following properties:

You can also consult the log property, which contains an array of hashes - one for each assertion - with the following properties:

Defined in: plan.js

Since:
SproutCore 1.0

Field Summary

Class Methods

Field Detail

CoreTest.Plan.fn

Any methods added to this hash will be made global just before the first test is run. You can add new methods to this hash to use them in unit tests. "this" will always be the test plan.

CoreTest.Plan.isRunning

If true then the test plan is currently running and items in the queue will execute in order.

Class Method Detail

begin()

Called when the test plan begins running. This method will notify the delegate. You will not normally call this method directly.

Returns:
CoreTest.Plan
receiver
clearHtmlbody()
create(attrs)

Define a new test plan instance. Optionally pass attributes to apply to the new plan object. Usually you will call this without arguments.

Parameters:
attrs Hash
plan arguments
Returns:
CoreTest.Plan
new instance/subclass
enabled(moduleName, testName)

Can be used to decide if a particular test should be enabled or not. Current implementation allows a test to run.

Parameters:
moduleName
testName
Returns:
Boolean
error(msg, e)

Called by a matcher to record that a test had an error. Requires a working test property.

Parameters:
msg
e
fail(msg)

Called by a matcher to record that a test has failed. Requires a working test property.

Parameters:
msg
finish()

When the test plan finishes running, this method will be called to notify the delegate that the plan as finished.

Returns:
CoreTest.Plan
receiver
htmlbody(string)

Converts the passed string into HTML and then appends it to the main body element. This is a useful way to automatically load fixture HTML into the main page.

Parameters:
string
module(desc, lifecycle)

Sets the current module information. This will be used when a test is added under the module.

Parameters:
desc
lifecycle
Returns:
CoreTest.Plan
receiver
now()
pass(msg)

Called by a matcher to record that a test has passed. Requires a working test property.

Parameters:
msg
pause()

Force the test plan to take a break. Avoids slow script warnings. This is called automatically after each test completes.

prepare()

Exports the comparison functions into the global namespace. This will allow you to call these methods from within testing functions. This method is called automatically just before the first test is run.

Returns:
CoreTest.Plan
receiver
process()

Processes items in the queue as long as isRunning remained true. When no further items are left in the queue, calls finish(). Usually you will not call this method directly. Instead call run().

Returns:
CoreTest.Plan
receiver
record(module, test, assertions, timings)

Records the results of a test. This will add the results to the log and notify the delegate. The passed assertions array should contain hashes with the result and message.

Parameters:
module
test
assertions
timings
reset()

Universal method can be called to reset the global state of the application for each test. The default implementation will reset any saved fixture.

run()

Initiates running the tests for the first time. This will add an item to the queue to call finish() on the plan when the run completes.

Returns:
CoreTest.Plan
receiver
setup(func)
Sets the current setup method.
Parameters:
func
Returns:
CoreTest.Plan
receiver
start()

Begins running the test plan after a slight delay to avoid interrupting any current callbacks.

Returns:
CoreTest.Plan
receiver
stop(timeout)

Stops the test plan from running any further. If you pass a timeout, it will raise an exception if the test plan does not begin executing with the allotted timeout.

Parameters:
timeout Number
optional timeout in msec
Returns:
CoreTest.Plan
receiver
synchronize(callback)

Primitive used to add callbacks to the test plan queue. Usually you will not want to call this method directly but instead use the module() or test() methods.

Parameters:
callback
Returns:
CoreTest.Plan
receiver
teardown(func)
Sets the current teardown method
Parameters:
func
Returns:
CoreTest.Plan
receiver
test(desc, func)
Generates a unit test, adding it to the test plan.
Parameters:
desc
func
warn(msg)

Called by a matcher to record that a test issued a warning. Requires a working test property.

Parameters:
msg
Documentation generated by JsDoc Toolkit 2.4.0 on Wed Apr 08 2015 10:02:20 GMT-0600 (CST)