Testing
- commands and classes for writing tests
package require Itcl
package require Testing
itcl::class MyTests {
inherit Testing::TestObject
method test_passing {} {
puts "Hello, I pass!"
}
method test_failing {} {
error "Hello, I'm about to fail!"
}
method test_with_assertion {} {
set a 0
set b 1
# will raise ::Testing::AssertionFailed
::Testing::assert {$a == $b}
}
::Testing::constraints {umts} {
method test_umts_connectivity {} {
# test code ...
}
}
}
exit [[MyTests #auto] run $::argv]
Testing::TestObject
is the base class for all native tests written using
the Caius framework. While it is not mandatory to derive tests from the
TestObject
class, it is highly recommended, as it provides built-in test
execution and reporting functionality via its run
method.
assert
{
expression }
::Testing::AssertionFailed
exception. The given expression is evaluated as by if
.constraints
constraints body
::Testing::constraints {unix nonRoot} {
# code executed if platform is Unix and user not root
}
Constraints can be set or unset with the set_constraint
command. There are a
number of pre-defined constraints:
unix
win
tempNotUnix
tempNotWin
unixCrash
winCrash
emptyTest
knownBug
nonPortable
userInteraction
pointer64
unixExecs
root
nonRoot
set_constraint
constraint boolean
test_constraints
constraints
method run
?-f
report_format? ?test test ...?method list_tests
TestObject
.method setup_before
[interface]method teardown_after
[interface]method setup
[interface]method teardown
[interface]All methods starting with the prefix test are considered test cases and
automatically invoked by the run
method.
itcl
(3)