This section is for the impatient who wanted to get started right away. Suppose you have file called file.scm. Create a file called file-test.scm. This file will contain the test cases.
At the top of file-test.scm import the SchemeUnit library:
(require (lib "test.ss" "schemeunit"))
Now were are going to create a test suite to hold all the tests for file.scm.
(define file-tests (make-test-suite "Tests for file.scm" ...))
Now we define test cases within the
file-tests test suite.
Let's assume that file.scm implements versions of
my--. We are going to test
my-- for integer arthimetic.
(define file-tests (make-test-suite "Tests for file.scm" (make-test-case "Simple addition" (assert = 2 (my-+ 1 1))) (make-test-case "Simple subtraction" (assert = 0 (my-- 1 1)))))
Above we implemented two simple test cases. Test cases fail if any
one of the assertions they contain fail. There are many predefined
assertions and you can define your own using the
define-assertion macro, but that's a bit complicated for a quick
Finally to run our tests we can either the graphical or textual user interfaces for SchemeUnit. We'll use the textual interface as its the simplest to setup. To file-test.scm we import the textual user interface, and then run our tests using it.
(require (lib "text-ui.ss" "schemeunit")) (test/text-ui file-tests)
Now we can execute this file in DrScheme and the textual user interface will report the success or failure of tests!