3

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?

Aditya Kappagantula
  • 564
  • 1
  • 7
  • 21

1 Answers1

4

Try this:

   testError
   |temp|
   temp := 5.
      self
         should: [(temp < 3) ifFalse:[
            self error: 'Invalid input']]
         raise: Error
David Buck
  • 2,847
  • 15
  • 16