开发者

Squeak - SUnit Testing for Errors

开发者 https://www.devze.com 2022-12-25 01:17 出处:网络
I have been suggested to use should:rise in my test case to test for errors that a method might raise. For some reason it does not work as expected, so I want to verify that I\'m doing it right. Here

I have been suggested to use should:rise in my test case to test for errors that a method might raise. For some reason it does not work as expected, so I want to verify that I'm doing it right. Here is the code in the test case:

self should: [aMyClass compareTo: 'This is a string'] raise: 'invalid input'.

My compareTo/1 method looks like this:

(aMyClass isKindOf: MyClass) ifFalse: [self error: 'invalid input'.].

The test开发者_运维百科 runner output is that there is "1 errors".

Thank you.


#should:raise: expects an Exception class as its second argument, similar to the first argument of #on:do: in exception handling:

 self should: [ aMyClass compareTo: 'This is a string' ] raise: Error
0

精彩评论

暂无评论...
验证码 换一张
取 消