<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><br></div><div>This first example shows how to use module+ test with test-engine:&nbsp;</div><div><br></div><div><div>#lang racket</div><div><br></div><div>(module+ test&nbsp;</div><div>&nbsp; (require test-engine/racket-tests))</div><div><br></div><div>;; Int -&gt; Int&nbsp;</div><div>;; adds 2 to n</div><div><br></div><div>(module+ test ;; setting up examples before you define the function&nbsp;</div><div>&nbsp; (check-expect (add2 3) 4)</div><div>&nbsp; (check-expect (add2 3) 5))</div><div><br></div><div>(define (add2 n)</div><div>&nbsp; (+ n 3))</div><div><br></div><div>(module+ test</div><div>&nbsp; (test)) ;; calling this function controls when you run the 'test suite'</div></div><div><br></div><div>All you need to know is that drracket requires submodules named test when you run the program, though this default can be changed via the language preference (see submodules to run, drop down menu). At the command line, racket test foo.rkt will require the test submodules but otherwise they are not run.&nbsp;</div><div><br></div><div>;; ---&nbsp;</div><div><br></div><div>This second example translates the first to rackunit:&nbsp;</div><div><br></div><div><div>#lang racket</div><div><br></div><div>(module+ test&nbsp;</div><div>&nbsp; (require rackunit))</div><div><br></div><div>;; Int -&gt; Int&nbsp;</div><div>;; adds 2 to n</div><div><br></div><div>(module+ test</div><div>&nbsp; (check-equal? (add2 3) 4)</div><div>&nbsp; (check-equal? (add2 3) 5))</div><div><br></div><div>(define (add2 n)</div><div>&nbsp; (+ n 2))</div><div><br></div><div>The tests are always run when you require the test submodule (see above).&nbsp;</div><div><br></div><div>;; ---&nbsp;</div><div><br></div><div>With rackunit, you can also define test-suites (see docs, especially define/provide-test-suite. You compose these test suites, provide them, and run them if and when you wish by loading the proper module.&nbsp;</div><div><br></div><div>Please search for an earlier post of mine where I explain a specific arrangement of separate modules to make all of this convenient.&nbsp;</div><div><br></div><div>With submodules, you can stick these test suites into submodules and require those in some global test module.&nbsp;</div><div><br></div><div>-- Matthias</div><div><br></div><div>&nbsp;&nbsp;</div></div><div><br></div><div><br></div><div><br></div><div><div>On Aug 7, 2012, at 10:31 PM, Joe Gilray wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">Hi Matthias,<div><br></div><div>I will take you up on your offer of an example... thanks!</div><div><br></div><div>I've read about test-suite and test-case, but I'm not sure of the best way to test each utility in a file.</div>
<div><br></div><div>Ideally the tests would be grouped with the functions:</div><div><br></div><div>(define f1 ...)</div><div>(module+ test&nbsp;</div><div>&nbsp; (test-equal? "f1-tests" (f1 1 2) 1)</div><div>&nbsp; (test-equal? "f1-tests" (f1 3 4) 4))</div>
<div><br></div><div><div>(define f2 ...)</div><div>(module+ test&nbsp;</div><div>&nbsp; (test-equal? "f2-tests" (f2 1 2) 1)</div><div>&nbsp; (test-equal? "f2-tests" (f2 3 4) 4))</div></div><div><br></div><div>etc.</div>
<div><br></div><div>I believe that the above scheme would work and run every time the enclosing file/module is run... right?</div><div><br></div><div>What if I want to control when all the tests are run? &nbsp;Can I somehow build a trigger to fire off all the tests? &nbsp;From the docs it looks like this is the purpose of test-suite, but I don't know the mechanics when the test cases are spread out in the file... maybe that isn't allowed and I will need to group the tests?</div>
<div><br></div><div>Thanks again,</div><div>-Joe<br><br><div class="gmail_quote">On Tue, Aug 7, 2012 at 6:00 PM, Matthias Felleisen <span dir="ltr">&lt;<a href="mailto:matthias@ccs.neu.edu" target="_blank">matthias@ccs.neu.edu</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im"><br>
On Aug 7, 2012, at 8:24 PM, Joe Gilray wrote:<br>
<br>
&gt; Now that 5.3 is out, I've been reading about submodules and their support for testing. &nbsp;In the past I used test-engine/racket-tests for testing.<br>
&gt;<br>
&gt; Can someone please give me a rundown of when to use rackunit and advantages/disadvantages of test-engine and rackunit?<br>
<br>
</div>-- test-engine provides test support for the teaching languages of DrRacket.<br>
-- rackunit is for 'adult' programmers, meaning programmers who have outgrown teaching languages.<br>
<br>
You can still use test-engine in plain #lang racket, and you could use rackunit in teaching languages.<br>
<br>
You can also use both with submodules especially (module+ test ...). Holler if you need examples -- Matthias<br>
<br>
<br>
<br>
<br>
</blockquote></div><br></div>
</blockquote></div><br></body></html>