[squeak-dev] BlockContextTest >> #testNew

Frank Shearar frank.shearar at gmail.com
Thu Jan 9 16:34:12 UTC 2014


On 9 January 2014 16:25, Chris Muller <asqueaker at gmail.com> wrote:
> Yea, the code definitely appears wrong for testing, but is it really
> useful to assert the *exact wording* of an error message, and
> duplicate it 4 times?
>
> I regard the messageText of Exceptions to be "for human consumption
> only".  Any time I see code that thinks its necessary to check the
> wording of an exception makes me want to say, "If you think you need
> to do that then you your own Exception subclass."

I do check error messages, but I only check for the presence of
particular things. Like the Inbox submission for SUnit I just posted,
I want to know that the messageText says "not identical". In other
words, I like to test that an error message is _useful_.

> So, of the 4 tests in this method, I think the second one should be
> removed, and the last two should be made like the first one (e.g.,
> without the string literals).

I'm with you on the removal of duplication. Personal preference would
be to say something like self assert: (e messageText
includesSubString: '#newForMethod').

I couldn't get #ifError: to work properly in a test, so for my
#assert:identical: tests I had a #should:raise: and then an on:do:
catching the same type of exception, and verifying the usefulness of
the error message.

frank

> On Thu, Jan 9, 2014 at 7:30 AM, Frank Shearar <frank.shearar at gmail.com> wrote:
>> testNew
>>     self should: [ContextPart new: 5] raise: Error.
>>     [ContextPart new: 5]
>>         ifError: [:error :receiver | error = 'Error: Contexts must
>> only be created with newForMethod:'].
>>     [ContextPart new]
>>         ifError: [:error :receiver | error = 'Error: Contexts must
>> only be created with newForMethod:'].
>>     [ContextPart basicNew]
>>         ifError: [:error :receiver | error = 'Error: Contexts must
>> only be created with newForMethod:'].
>>
>> Surely those "error = " lines need asserts?
>>
>> frank
>>
>


More information about the Squeak-dev mailing list