Previous: srfi testing spec results, Up: srfi testing spec [Index]
This section specifies how to write a test-runner. It can be ignored if you just want to write test cases.
These callback functions are “methods”" (in the object–oriented
sense) of a test-runner. A method test-runner-on-event
is called
by the implementation when event happens.
To define (set) the callback function for event use the following expression. (This is normally done when initializing a test-runner.)
(test-runner-on-event! runner event-function)
An event-function takes a test-runner argument, and possibly other arguments, depending on the event.
To extract (get) the callback function for event do this:
(test-runner-on-event runner)
To extract call the callback function for event use the following expression. (This is normally done by the implementation core.)
((test-runner-on-event runner) runner other-args ...)
The following callback hooks are available.
The on-test-begin-function is called at the start of an individual testcase, before the test expression (and expected value) are evaluated.
The on-test-end-function is called at the end of an individual testcase, when the result of the test is available.
The on-group-begin-function is called by a test-begin
,
including at the start of a test-group
. The suite-name is
a Scheme string, and count is an integer or #f
.
The on-group-end-function is called by a test-end
,
including at the end of a test-group
.
Called from test-end
(before the on-group-end-function is
called) if an expected-count was specified by the matching
test-begin
and the expected-count does not match the
actual-count of tests actually executed or skipped.
Called from test-end
(before the on-group-end-function is
called) if a suite-name was specified, and it did not that the
name in the matching test-begin
.
The on-final-function takes one parameter (a test-runner) and
typically displays a summary (count) of the tests. The
on-final-function is called after called the
on-group-end-function correspondiong to the outermost
test-end
. The default value is test-on-final-simple
which
writes to the standard output port the number of tests of the various
kinds.
The default test-runner returned by test-runner-simple
uses the
following callback functions:
(test-on-test-begin-simple runner) (test-on-test-end-simple runner) (test-on-group-begin-simple runner suite-name count) (test-on-group-end-simple runner) (test-on-bad-count-simple runner actual-count expected-count) (test-on-bad-end-name-simple runner begin-name end-name)
You can call those if you want to write your own test-runner.
The following functions are for accessing the other components of a test-runner. They would normally only be used to write a new test-runner or a match-predicate.
Return the number of tests that passed, and were expected to pass.
Return the number of tests that failed, but were expected to pass.
Return the number of tests that passed, but were expected to fail.
Returns the number of tests that failed, and were expected to pass.
Return the number of tests or test groups that were skipped.
Return the name of the current test or test group, as a string. During
execution of test-begin
this is the name of the test group;
during the execution of an actual test, this is the name of the
test-case. If no name was specified, the name is the empty string.
A list of names of groups we’re nested in, with the outermost group first.
A list of names of groups we’re nested in, with the outermost group
last. (This is more efficient than test-runner-group-path
, since
it doesn’t require any copying.)
Get or set the aux-value field of a test-runner. This field is
not used by this API or the test-runner-simple
test-runner,
but may be used by custom test-runners to store extra state.
Reset the state of the runner to its initial state.
This is an example of a simple custom test-runner. Loading this program before running a test-suite will install it as the default test runner.
(define (my-simple-runner filename) (let ((runner (test-runner-null)) (port (open-output-file filename)) (num-passed 0) (num-failed 0)) (test-runner-on-test-end! runner (lambda (runner) (case (test-result-kind runner) ((pass xpass) (set! num-passed (+ num-passed 1))) ((fail xfail) (set! num-failed (+ num-failed 1))) (else #t)))) (test-runner-on-final! runner (lambda (runner) (format port "Passing tests: ~d.~%Failing tests: ~d.~%" num-passed num-failed) (close-output-port port))) runner)) (test-runner-factory (lambda () (my-simple-runner "/tmp/my-test.log")))
Previous: srfi testing spec results, Up: srfi testing spec [Index]