If your students are beginners, I urge you to use teaching languages in 
DrRacket instead. Like the language itself, the testing framework is adapted 
for beginners to avoid basic complexities, such as those below. For example, 

 (check-error (f 10) "error") 

is all you need to test a function/method f that may raise an error with 
message "error". 

If your students are advanced, I think that lambda is easier for exn-s than 
Java's jUnit constructions. Nevertheless I agree that testing exns could be 
done in syntactically much much much simpler way in a language with the richest 
system of syntax extensions. 

-- Matthias






On Aug 27, 2013, at 7:48 PM, George Rudolph wrote:

> I understand the idea of refactoring code to make it testable.
> I very much appreciate the clarification on usage. Thank you.
> But...
> As I see it, this approach to testing code is beyond counterintuitive,
> at least at first glance.  It takes a moment to realize that wrapping 
> the test call in a lambda definition or a thunk is basically creating a 
> delayed unit of computation. Not something I want to teach my students about
> during the first week of class, I think.
> 
> What I intend to do is require them to unit test their code before they 
> submit it.
> I have never used rackunit before, so I thought I would give it a try before 
> I make them use it.
> IS testing really this complex, or am I missing some larger idea here?
> 
> George
> 
> -----Original Message-----
> From: Asumu Takikawa [mailto:as...@ccs.neu.edu] 
> Sent: Tuesday, August 27, 2013 4:35 PM
> To: George Rudolph
> Cc: users@racket-lang.org
> Subject: Re: [racket] Help with exception raising and testing
> 
> On 2013-08-27 14:33:54 -0400, George Rudolph wrote:
>>   #lang racket
>> 
>>   (require rackunit "mybasic.rkt")
>> 
>>   (test-exn "negative coin" negative? (sum-coins -1 3 5 7) )
> 
> There is a common mistake here that myself and other Racket programmers 
> frequently make. The various rackunit functions that deal with exceptions 
> take a *thunk* that contains the code to run.
> 
> So `(sum-coins -1 3 5 7)` should be `(λ () (sum-coins -1 3 5 7))` or `(thunk 
> (sum-coins -1 3 5 7))`.
> 
> In addition, the test predicate should take an exception value so `negative?` 
> won't work. You probably want a predicate like `(λ (e) (regexp-match 
> #rx"negative?" (exn-message e)))` instead.
> 
> Cheers,
> Asumu
> 
> 
> ____________________
>  Racket Users list:
>  http://lists.racket-lang.org/users


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

Reply via email to