[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

9.21 gauche.test - Unit Testing

Module: gauche.test
Defines a set of functions to write test scripts. A test script will look like this:
 
(use gauche.test)
(test-start "my feature")
(load "my-feature")  ; load your program
(import my-feature)  ; if your program defines a module.

(test-section "feature group 1")
(test "feature 1-1" EXPECT (lambda () TEST-BODY))
(test "feature 1-2" EXPECT (lambda () TEST-BODY))
 ...

(test-section "feature group 2")
(define test-data ...)
(test "feature 2-1" EXPECT (lambda () TEST-BODY))
 ...

(test-end)

With this convention, you can run test both interactively or in batch. To run a test interactively, just load the file and it reports a result of each test, as well as the summary of failed test at the end. To run a test in batch, it is convenient to redirect the stdout to some file If stdout is redirected to other than tty, all the verbose logs will go there, and only a small amount of messages go to stderr.

It is recommended to have a "test" target always in Makefile of your module/program, so that the user of your program can run a test easily. The rule may look like this:

 
test :
        gosh my-feature-test.scm > test.log

Function: test name expected thunk &optional =
Calls thunk, and compares its result with expected. The comparison predicate is equal? by default, but you can specify your own predicate by the argument =. Name is a name of the test, for logging purpose.

Function: test-start module-name
Initializes internal state and prints a log header. This should be called before any tests. Module-name is used only for logging purpose.

Function: test-section section-name
Marks beginning of the group of tests. This is just for logging.

Function: test-end
Prints out list of failed tests.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

This document was generated by Ken Dickey on November, 28 2002 using texi2html