Help with SUnit

Michael Roberts mike at
Thu Jan 22 17:27:42 UTC 2004

I've got myself a bit confused with SUnit and was hoping someone might be able to help out.  This feels like a bug but much of the time I just need to learn some more Squeak!  I feel desperately stupid because I can't find what I'm doing wrong!

I have a test class with one instance variable 'stream'.  I have attached the file but it is easy enough to walk through its three methods.

	stream _ WriteStream on: ''

	stream _ nil

	self assert: stream notNil.
	stream nextPutAll: 'I have a cunning plan'.
	self assert: false

The thing that is confusing me is this:
1) the test should fail on the last line.  You can set this to true to check it passes.

2) SUnit brings up a debugger on the failing test but stream is nil so you can't get past the first line.  I have started to walk through this code and below is my idea so far...

TestCase>>runAsFailure: does a self setUp followed by self openDebuggerOnFailingTestMethod which in turn runs the test in its own process and attaches the debugger.

3) When the debugger runs, however, stream is nil as illustrated by the position of the debugger highlight and checking the object's state.  I'm guessing that somewhere the test execution is stopped at the first error. this isn't the line that caused the assertion though. 

If I put some self halts into SUnit (probably a bad idea, I eventually get code simulation errors etc) I can run through the original execution of the test to see that it asserts on the last line.  I can then watch the failed test get setup correctly and see a valid stream instance variable.

4) I get a valid instance variable by stepping into openDebuggerOnFailingTestMethod but can't go any further.

5) If I put a self halt in tearDown (feeling on dodgy ground now) something is sending tearDown to the test the instance after the debugger is opened on the failing test. I can then confirm that the test instance is now not valid.

6) If I look at the stack of what is sending tearDown it's coming from here

runCaseAsFailure: aSemaphore
	[self setUp.
	self openDebuggerOnFailingTestMethod] sunitEnsure: [
		self tearDown.
		aSemaphore signal]

which should be the same place that opened the debugger earlier.  

7) how does the block to sunitEnsure: wait for openDebuggerOnFailingTestMethod to finish?  It should just be a normal block being sent >>value.

If openDebuggerOnFailingTestMethod waits until the debugger is closed then the ensure block shouldn't get called.  If openDebuggerOnFailingTestMethod doesn't stop then the test instance gets clobbered by the ensure block?

I'm a bit lost in this method!

8) surely I'm doing something daft right? :-)


-------------- next part --------------
'From Squeak3.7alpha of ''11 September 2003'' [latest update: #5657] on 22 January 2004 at 4:39:27 pm'!
TestCase subclass: #MikeIsConfusedTest
	instanceVariableNames: 'stream'
	classVariableNames: ''
	poolDictionaries: ''
	category: 'SUnitTests'!

!MikeIsConfusedTest methodsFor: 'as yet unclassified' stamp: 'mjr 1/22/2004 16:28'!
	stream _ WriteStream on: ''! !

!MikeIsConfusedTest methodsFor: 'as yet unclassified' stamp: 'mjr 1/22/2004 16:29'!
	stream _ nil! !

!MikeIsConfusedTest methodsFor: 'as yet unclassified' stamp: 'mjr 1/22/2004 16:35'!
	self assert: stream notNil.
	stream nextPutAll: 'I have a cunning plan'.
	self assert: false! !

More information about the Squeak-dev mailing list