[plt-scheme] Setup and teardown in SchemeUnit

From: Michał Kwiatkowski (constant.beta at gmail.com)
Date: Mon Dec 1 16:24:10 EST 2008

On Mon, Dec 1, 2008 at 8:54 AM, Noel Welsh <noelwelsh at gmail.com> wrote:
> And it's a brand new day...
> Abstract over a test-case with the setup you want:
> (define-syntax my-test-case
>  (syntax-rules ()
>    [(my-test-case name expr ...)
>     (test-case  name (before (my-before-expr) expr ...))]))
> (my-test-case (+ 1 1))
> (my-test-case (+ 2 2))
> ...

That isn't much of an improvement, as I'd have to make a macro for
each fixture and tests using the same fixture won't be bundled

I was thinking more of something looking like this:

(test-suite "Test suite with a fixture."
    #:setup (lambda () (display "Setup\n"))
    #:teardown (lambda () (display "Teardown\n"))
    (test-case "Test case 1" (display "#1\n"))
    (test-case "Test case 2" (display "#2\n")))

Running this test would then print:

> A class is the main unit of abstraction in Java/Python, with
> overloading the main method of extension.  In Scheme its a functions
> and function parameterisation respectively, so the mechanism of
> setup/teardown changes to match the language (and I use a macro above
> for reasons that aren't really important).

I don't see how available methods of abstraction affect this use case.
I use Scheme and I still need the setup/teardown behavior. I'm
surprised this pattern isn't included in SchemeUnit by default, as
it's common when testing for side-effects.

> Adding setup/teardown arguments to test-begin/test-case is something
> that might be worth doing.  In my experience I don't need this often
> enough to justify it.

What about adding adding setup/teardown arguments to test-suite, as
shown in an example above? Is there a chance it would be included in
the next release of SchemeUnit if I implemented this myself?


Posted on the users mailing list.