Class('Test.Run.Test', {
have : {
url : null,
assertPlanned : null,
assertCount : 0,
diagCount : 0,
passCount : 0,
failCount : 0,
results : null,
run : null,
harness : null,
failed : false,
failedException : null,
startDate : null,
execEnd : null,
topScope : null,
passThroughEx : false
},
after : {
initialize : function (config) {
// if (typeof this.run != 'function') throw "The body of test absent"
this.results = []
}
},
methods : {
toString : function() {
return this.url
},
plan : function (value) {
if (this.assertPlanned != null) throw "Test plan can't be changed"
this.assertPlanned = value;
},
addResult : function (result) {
if (this.assertPlanned == null && this.assertCount) throw "Plan wasn't setuped"
this.results.push(result)
this.harness.testUpdate(this, result)
},
diag : function (desc) {
this.diagCount++
this.addResult(new Test.Run.Result.Diagnostic({
description : desc
}))
},
//XXX pass&fail should be more flexible and overridable (for TODO, SKIP, etc)
pass : function (desc) {
this.passCount++
this.addResult(new Test.Run.Result.Assertion({
pass : true,
description : desc,
indx : ++this.assertCount
}))
},
fail : function (desc) {
this.failCount++
this.addResult(new Test.Run.Result.Assertion({
pass : false,
description : desc,
indx : ++this.assertCount
}))
},
ok : function (condition, desc) {
if (condition) this.pass(desc); else this.fail(desc)
},
is : function (got, expected, desc) {
this.ok(got == expected, desc)
},
start : function () {
this.startDate = new Date()
this.harness.testStart(this)
var me = this
var run = this.run
if (this.passThroughEx)
run(me)
else
var e = this.topScope.__EXCEPTION_CATCHER__(function(){
run(me)
})
if (e) {
this.failed = true
this.failedException = e
this.harness.testFail(this, e)
this.finalize()
// if (this.passThroughEx) throw e
return
}
this.finalize()
},
finalize : function () {
this.execEnd = new Date()
this.harness.testEnd(this)
},
getSummaryMessage : function () {
var res = []
var passCount = this.passCount
var failCount = this.failCount
res.push('Passed: ' + passCount)
res.push('Failed: ' + failCount)
if (!this.failed) {
if (failCount + passCount < this.assertPlanned) res.push('Looks like you planned ' + this.assertPlanned + ' tests, but ran only ' + (failCount + passCount))
if (failCount + passCount > this.assertPlanned)
res.push('Looks like you planned ' + this.assertPlanned + ' tests, but ran ' + (failCount + passCount - this.assertPlanned) + ' extra tests, ' + (failCount + passCount) + ' total.')
if (passCount == this.assertPlanned && !failCount) res.push('All tests successfull')
} else {
res.push('Test suite threw an exception: ' + this.failedException)
}
return res
},
isPassed : function () {
return !this.failed && !this.failCount && this.passCount >= this.assertPlanned
}
}
})
//eof Test.Run.Test
/**
Name
====
Test.Run.Test - Base class for individual test file
SYNOPSIS
========
t.plan(1)
t.ok(1 == 1, 'Indeed')
t.is(2 * 2, '4', 'Indeed')
t.pass('Some assertion is correct')
DESCRIPTION
===========
`Test.Run.Test` is a base testing class in Test.Run hierarchy. Its not supposed to be created manually, instead, the harness will create it for you.
This is a very base class, determining mostly the interface for the test object, its subclasses implements more useful assertion checks.
See [Test.Run.Test.Browser] and [Test.Run.Test.More]
ISA
===
[Joose.Meta.Object](http://openjsan.org/go?l=Joose.Meta.Object)
DOES
====
[Test.Run.Test.More]
USAGE
=====
Below is the list of methods, intended for usage in the individual tests.
### plan
> `void plan(Number tests)`
> This method setups test's plan. It should be called before any assertions were checked.
> **tests** - a number of planned assertions in this test file.
### diag
> `void diag(String text)`
> This method add the diagnostic message into results queue. The actual presentation logic of the message is delegated to harness.
> **text** - The text of diagnostic message
### pass
> `void pass(String text)`
> This method add the passed assertion into results queue. The actual presentation logic of the passed assertion is delegated to harness.
> **text** - The text of the assertion
### fail
> `void fail(String text)`
> This method add the failed assertion into results queue. The actual presentation logic of the passed assertion is delegated to harness.
> **text** - The text of the assertion
### ok
> `void ok(Boolean condition, String text)`
> This method add the passed or failed assertion into results queue. The type of assertion to add is determined from 1st argument.
> **condition** - The boolean condition, indicating wheter assertions is passed or failed
> **text** - The text of the assertion
### is
> `void is(Object value1, Object value2, String text)`
> This method add the passed or failed assertion into results queue. The type of assertion to add is determined from comparison of 1st and 2nd arguments.
Comparison is performed with '==' operator
> **value1** - The 1st value for comparison
> **value2** - The 2nd value for comparison
> **text** - The text of the assertion
ATTRIBUTES
==========
### url
> `String url`
> Url of the test file.
### assertPlanned
> `Number assertPlanned`
> Planned number of assertions to test.
### assertCount
> `Number assertCount`
> Current number of processed assertions (not includes the diagnostic messages).
### diagCount
> `Number diagCount`
> Current number of processed diagnostic messages.
### passCount
> `Number passCount`
> Current number of passed assertions.
### failCount
> `Number failCount`
> Current number of failed assertions.
### results
> `Test.Run.Result[] results`
> Array of [Test.Run.Result] instances (represent either assertion or diagnostic message).
### run
> `Function run`
> The function, which contain test statements (is invoking with `StartTest` and will receive the instance of this class (or subclass) as a single argument)
### harness
> `Test.Run.Harness harness`
> Reference to [Test.Run.Harness] (or subclass) instance, which represents the harness, under which the test is running.
#### failed
> `Boolean failed`
> The sign whether the test has threw an exception.
### failedException
> `Object failedException`
> Thrown exception (see also [failed])
### startDate
> `Date startDate`
> Timestamp of test start
### execEnd
> `Date execEnd`
> Timestamp of test end
### topScope
> `Object topScope`
> The top scope object in which test function was declared (an iframe or window in which test is running)
### passThroughEx
> `Boolean passThroughEx`
> The sign whether the test should re-throw any exceptions caught (useful for debugging with FireBug). Defaults to 'false'
METHODS
=======
### toString
> `String toString()`
> Return string presentation of this test. Defaults to value of 'url' property
### addResult
> `void addResult(Test.Run.Result result)`
> This method adds the instance of [Test.Run.Result] to results queue. The result can be either assertion ([Test.Run.Result.Assertion]) or diagnostic message ([Test.Run.Result.Diagnostic])
> **result** - The result instance to add
### start
> `protected void start()`
> This method starts the test execution. Execution is performing by running the function in the 'run' attribute.
### finalize
> `protected void finalize()`
> This method is called when the test finished execution. It setup the 'execEnd' attribute
### getSummaryMessage
> `protected String[] getSummaryMessage()`
> This method returns the summary message for this test. Should be called after the test has finished execution.
### isPassed
> `protected Boolean isPassed()`
> This method returns the sign whether the whole test passed or failed. The test is considered passed, when a) no exceptions were thrown,
b) there is no failing assertions c) the number of passed assertions is greater or equal to planned assertions number.
SEE ALSO
========
Subclass of this class, intended to run on browser platform: [Test.Run.Test.Browser]
General documentation for Joose: [http://openjsan.org/go/?l=Joose](http://openjsan.org/go/?l=Joose)
BUGS
====
All complex software has bugs lurking in it, and this module is no exception.
Please report any bugs through the web interface at [http://github.com/SamuraiJack/Module-Stub/issues](http://github.com/SamuraiJack/Module-Stub/issues)
AUTHORS
=======
Nickolay Platonov [nplatonov@cpan.org](mailto:nplatonov@cpan.org)
COPYRIGHT AND LICENSE
=====================
Copyright (c) 2009, Nickolay Platonov
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* Neither the name of Nickolay Platonov nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
[Test.Run.Result]: Result.html
[Test.Run.Harness]: Harness.html
[Test.Run.Test.Browser]: Test/Browser.html
[Test.Run.Test.More]: Test/More.html
*/