The submodules are woven together so wrapping (test) with (time ...) should 
work fine. 


On Aug 8, 2012, at 4:18 PM, Joe Gilray wrote:

> Thanks Matthias,
> 
> Is there an easy way to "internally" time the duration of all tests?  with 
> test-engine I could use (time (test)), with all the tests in a test submodule 
> do I have to do the timing externally?  I.e "TimeThis raco test myfile.rkt"?
> 
> -Joe
> 
> On Wed, Aug 8, 2012 at 6:31 AM, Matthias Felleisen <matth...@ccs.neu.edu> 
> wrote:
> 
> This first example shows how to use module+ test with test-engine: 
> 
> #lang racket
> 
> (module+ test 
>   (require test-engine/racket-tests))
> 
> ;; Int -> Int 
> ;; adds 2 to n
> 
> (module+ test ;; setting up examples before you define the function 
>   (check-expect (add2 3) 4)
>   (check-expect (add2 3) 5))
> 
> (define (add2 n)
>   (+ n 3))
> 
> (module+ test
>   (test)) ;; calling this function controls when you run the 'test suite'
> 
> 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. 
> 
> ;; --- 
> 
> This second example translates the first to rackunit: 
> 
> #lang racket
> 
> (module+ test 
>   (require rackunit))
> 
> ;; Int -> Int 
> ;; adds 2 to n
> 
> (module+ test
>   (check-equal? (add2 3) 4)
>   (check-equal? (add2 3) 5))
> 
> (define (add2 n)
>   (+ n 2))
> 
> The tests are always run when you require the test submodule (see above). 
> 
> ;; --- 
> 
> 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. 
> 
> Please search for an earlier post of mine where I explain a specific 
> arrangement of separate modules to make all of this convenient. 
> 
> With submodules, you can stick these test suites into submodules and require 
> those in some global test module. 
> 
> -- Matthias
> 
>   
> 
> 
> 
> On Aug 7, 2012, at 10:31 PM, Joe Gilray wrote:
> 
>> Hi Matthias,
>> 
>> I will take you up on your offer of an example... thanks!
>> 
>> 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.
>> 
>> Ideally the tests would be grouped with the functions:
>> 
>> (define f1 ...)
>> (module+ test 
>>   (test-equal? "f1-tests" (f1 1 2) 1)
>>   (test-equal? "f1-tests" (f1 3 4) 4))
>> 
>> (define f2 ...)
>> (module+ test 
>>   (test-equal? "f2-tests" (f2 1 2) 1)
>>   (test-equal? "f2-tests" (f2 3 4) 4))
>> 
>> etc.
>> 
>> I believe that the above scheme would work and run every time the enclosing 
>> file/module is run... right?
>> 
>> What if I want to control when all the tests are run?  Can I somehow build a 
>> trigger to fire off all the tests?  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?
>> 
>> Thanks again,
>> -Joe
>> 
>> On Tue, Aug 7, 2012 at 6:00 PM, Matthias Felleisen <matth...@ccs.neu.edu> 
>> wrote:
>> 
>> On Aug 7, 2012, at 8:24 PM, Joe Gilray wrote:
>> 
>> > Now that 5.3 is out, I've been reading about submodules and their support 
>> > for testing.  In the past I used test-engine/racket-tests for testing.
>> >
>> > Can someone please give me a rundown of when to use rackunit and 
>> > advantages/disadvantages of test-engine and rackunit?
>> 
>> -- test-engine provides test support for the teaching languages of DrRacket.
>> -- rackunit is for 'adult' programmers, meaning programmers who have 
>> outgrown teaching languages.
>> 
>> You can still use test-engine in plain #lang racket, and you could use 
>> rackunit in teaching languages.
>> 
>> You can also use both with submodules especially (module+ test ...). Holler 
>> if you need examples -- Matthias
>> 
>> 
>> 
>> 
>> 
> 
> 

Attachment: smime.p7s
Description: S/MIME cryptographic signature

____________________
  Racket Users list:
  http://lists.racket-lang.org/users

Reply via email to