About use of specific error

Marcus Denker denker at iam.unibe.ch
Fri Mar 17 06:27:58 UTC 2006


On 17.03.2006, at 05:37, Diego Fernandez wrote:

>
>
> On 3/2/06, stéphane ducasse <ducasse at iam.unibe.ch > wrote:
> I was not talking about teaching anything.
> I just asked them to write tests and I was surprised that I have to
> catch always Error and not more precise Exception.
>
>
> About catching exceptions in tests.
> At Mercap, Hernan Wilkinson added a method to TestCase to simplify  
> testing of exceptions, ie:
>
> self should: [ "... " ]
> raise: XxxException withSignalDo: [:signal | self assert: signal  
> description notEmpty ].
>
> It's very useful to do assertions on the exception :)
>


In Squeak, there is already an SUnit extension for testing for  
description substrings (I think Ned added that):

self should: [....] raise: Error whoseDescriptionIncludes: 'string'


> Here is the change set to implement it in Squeak (I have changed  
> the selector to #should:raise:withExceptionDo: since in Squeak are  
> exceptions not signals)
>
> <SUnit exception assertions.1.cs>

Nice! I might add that to Squeak SUnit.

      Marcus


More information about the Squeak-dev mailing list