Test.Run.Test - Class, representing the individual test file
t.ok(1 == 1, 'Indeed')
t.is(2 * 2, '4', 'Indeed')
t.pass('Some assertion is correct')
t.done()
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.
Below is the list of methods, intended for usage in the individual tests.
void plan(Number tests)
This method setups test's plan. When used, it should be called before any assertions were checked.
tests - a number of planned assertions in this test file.
void done()
This method indicates that you've done testing and all assertions have been ran. It should be called after any assertions were checked.
void diag(String text)
This method output the diagnostic message. The actual presentation logic of the message is delegated to harness.
text - The text of diagnostic message
void pass(String text)
This method add the passed assertion into results queue.
text - The description of the assertion
void fail(String text)
This method add the failed assertion into results queue.
text - The description of the assertion
void ok(Boolean condition, String text)
This assertion passes when the supplied
condition
evalutes totrue
and fails otherwise.condition - The boolean condition, indicating wheter assertions is passed or failed
text - The description of the assertion
void notOk(Boolean condition, String text)
This is a reverse of
ok
(test passes when condition is false)
void is(Object value1, Object value2, String text)
This assertion passes when comparison of 1st and 2nd arguments shows that they are equal. Comparison is performed with '==' operator
value1 - The 1st value for comparison
value2 - The 2nd value for comparison
text - The description of the assertion
void is_deeply(Object value1, Object value2, String text)
This assertion passes when in-depth comparison of 1st and 2nd arguments (which are assumed to be JSON objects) shows that they are equal. Comparison is performed with '==' operator
This method has a synonym: isDeeply
value1 - The 1st value for comparison
value2 - The 2nd value for comparison
text - The description of the assertion
void isnt(Object value1, Object value2, String text)
This method is a reverse of
is
(passes when the operands are different).
Number beginAsync(Number? maxTime)
This method starts the "asynchronous frame". The test will not finished, until the frame will not be finished with endAsync call. endAsync will be automatically called after specified
maxtime
.maxTime - the maximum time (in ms) to wait until explicitly finalize this async frame. Default time is 10000 ms.
return - The timeoutId, which can be used in endAsync call
void endAsync(Number timeoutId)
This method finalize the "asynchronous frame" started with beginAsync.
timeoutId - The timeoutId, returned by beginAsync call
void like(String str, String|RegExp regex, String text)
This assertion passes when the passed
str
(1st argument) matches to a regular expressionregex
(2nd argument)str - The string to test
regex - The regex against which to test the string, can be also a plain string
text - The description of the assertion
void unlike(String str, String|RegExp regex, String text)
This method is the opposite of 'like', it adds failed assertion, when the string matches the passed regex.
str - The string to test
regex - The regex against which to test the string, can be also a plain string
text - The description of the assertion
void throwsOk(Function func, String|RegExp expected, String text)
This assertion is passed, when the
func
function throws the exception during executing, and the stringified exception passes the 'like' assertion (with 'expected' parameter). This method has a synonym: throws_okfunc - The function which supposed to throw an exception
expected - The regex against which to test the stringified exception, can be also a plain string
text - The description of the assertion
void livesOk(Function func, String text)
This assertion passes, when the supplied
func
function doesn't throw the exception during execution. This method has a synonym: lives_okfunc - The function which supposed to not throw an exception
text - The description of the assertion
void isaOk(Object value, Function/String class, String text)
This assertion passes, when the supplied
value
is the instance of theclass
. The check is performed withinstanceof
operator. Theclass
parameter can be supplied as class constructor or as string, representing the class name. In this case theclass
will eval'ed to receive the class constructor.
This method has a synonym: isa_ok
value - The value to check for 'isa' relationship
class - The class to check for 'isa' relationship with
value
text - The description of the assertion
void skipIf(Boolean condition, String why, Function code, Number? howMany)
This methods check the supplied
condition
and if its true then do not executes the supplied code. Instead, it addshowMany
pseudo-passed assertions to the test suite. If the condition is false, then it just run thecode
function.
This method is useful for skipping parts of the test suite, for example if the functionality being tested is not supported on the current platform.
condition - The boolean condition, indicating whether to run or skip the
code
why - The reason for the skip
code - A function, wrapping the assertions which needs to be skipped
howMany - Optional. A number of pseudo-passed assertions to add, when skipping real ones. Defaults to 1.
void skip(String why, Function code, Number? howMany)
Unconditional
skipIf
(always skips the code).
void todo(String why, Function code)
With this method you can mark part of the test suite as "todo", assuming it most probably will fail, but its still worth to try run them.
The supplied
code
function will be run, it will receive a new test instance as the 1st argument, which must be used for assertions checks (not the primary test instance, received fromStartTest
).Assertions, failed inside the
code
block will be treated by harness normally. Assertions, passed inside thecode
block will be treated by harness as bonus ones and highlighted.why - The reason/description for the todo
code - A function, wrapping the "todo" assertions. This function will receive a special test class instance which should be used for assertions checks.
General documentation for Joose: http://joose.github.com/Joose/
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/test.run/issues
Nickolay Platonov nplatonov@cpan.org
Copyright (c) 2010, 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:
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.