About use of specific error

Bany, Michel mbany at cincom.com
Fri Mar 3 10:18:52 UTC 2006


 

> I'm teaching them to write tests and to write tests for a 
> class that raises exceptions you have to catch them and to 
> cover the potential behavior of the class! This is not my 
> wish or not to have exceptions, they are there and to cover 
> the method behavior (because of different programming
> style) I have to cover them.
> 
> For example, what happens if we access an element at not 
> existing index.

Why not have your students write tests like this

IntervalTest >> testRemove

      self should: [(1 to: 3) remove: 2] raise: Exception.

      [(1 to: 3) remove: 2]
		on: Exception do: 

		[:ex |
		self assert: ex class == Error.
		self assert: ex description = 'elements cannot be
removed from an Interval'].

This clearly describes what is expected from the Interval class.

Michel.



More information about the Squeak-dev mailing list