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:
- assertions -- the total number of assertions
- tests -- the total number of tests
- passed -- number of assertions that passed
- failed -- number of assertions that failed
- errors -- number of assertions with errors
- warnings -- number of assertions with warnings
You can also consult the log property, which contains an array of hashes - one for each assertion - with the following properties:
- module -- module descriptions
- test -- test description
- message -- assertion description
- result --
CoreTest.OK
,CoreTest.FAILED
,CoreTest.ERROR
,CoreTest.WARN
Defined in: plan.js
- Since:
- SproutCore 1.0
Field Summary
Class Methods
- begin()
- clearHtmlbody()
- create(attrs)
- enabled(moduleName, testName)
- error(msg, e)
- fail(msg)
- finish()
- htmlbody(string)
- module(desc, lifecycle)
- now()
- pass(msg)
- pause()
- prepare()
- process()
- record(module, test, assertions, timings)
- reset()
- run()
- setup(func)
- start()
- stop(timeout)
- synchronize(callback)
- teardown(func)
- test(desc, func)
- warn(msg)
Field Detail
CoreTest.Plan.fnAny 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.
If true then the test plan is currently running and items in the queue will execute in order.
Class Method Detail
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
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
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
Called by a matcher to record that a test had an error. Requires a working test property.
- Parameters:
- msg
- e
Called by a matcher to record that a test has failed. Requires a working test property.
- Parameters:
- msg
When the test plan finishes running, this method will be called to notify the delegate that the plan as finished.
- Returns:
- CoreTest.Plan
- receiver
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
Sets the current module information. This will be used when a test is added under the module.
- Parameters:
- desc
- lifecycle
- Returns:
- CoreTest.Plan
- receiver
Called by a matcher to record that a test has passed. Requires a working test property.
- Parameters:
- msg
Force the test plan to take a break. Avoids slow script warnings. This is called automatically after each test completes.
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
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
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
Universal method can be called to reset the global state of the application for each test. The default implementation will reset any saved fixture.
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
- Parameters:
- func
- Returns:
- CoreTest.Plan
- receiver
Begins running the test plan after a slight delay to avoid interrupting any current callbacks.
- Returns:
- CoreTest.Plan
- receiver
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
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
- Parameters:
- func
- Returns:
- CoreTest.Plan
- receiver
- Parameters:
- desc
- func
Called by a matcher to record that a test issued a warning. Requires a working test property.
- Parameters:
- msg