Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visualworks Cincom Smalltalk SUnit Test case for error condition

I have this piece of code.

|temp|
temp := 5
(temp < 3) ifFalse:[
    self error: 'Invalid input'.
].

What will a SUnit test case look like, if I have to test that the above error is raised when I run this code?

Currently when I run the above code, it says "Unhandled exception: Invalid input" How can I handle this exception?

like image 647
Aditya Kappagantula Avatar asked Jan 25 '26 18:01

Aditya Kappagantula


1 Answers

Try this:

   testError
   |temp|
   temp := 5.
      self
         should: [(temp < 3) ifFalse:[
            self error: 'Invalid input']]
         raise: Error
like image 187
David Buck Avatar answered Jan 27 '26 08:01

David Buck



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!