[HOWTO] write a SUnit test

Daniel Vainsencher danielv at netvision.net.il
Fri Oct 24 23:21:51 UTC 2003


I updated http://minnow.cc.gatech.edu/squeak/3093 to include this. Only
problem I see with it is that the example will expire if we ever harvest
that fix...

Daniel

Marcus Denker <marcus at ira.uka.de> wrote:
> So,
> 
> for those who don't know yet howto write a Sunit test, here's
> a short tutorial.
> 
> The general idea is that if you find a bug that you like to
> see fixed, the best thing to do is to provide a test.
> 
> So, lets see. We have a current open [BUG] (with fix) that
> is nice as an example. 
> 
> The Bug: go to the "Supplies" Flap, and drag out that yellow
> "Press me" button. Now bring up a halo. There is a special
> Halo-button just for this kind of "Scriptable Button": on the
> down-right, left of the yellow one. press it. Ups.
> 
> Yoshiki has sent a Fix for this. Which was (of course, as is
> tradition in the Squeak Communty) not harvested. So, maybe
> we could add a test, so instead of ignoring the fix, we can
> ignore the failing test in the future (hey, a *clear* improvement!).
> 
> To do this, just we make a new class 
> 
> TestCase subclass: #ScriptableButtonTest
> 	instanceVariableNames: 'button '
> 	classVariableNames: ''
> 	poolDictionaries: ''
> 	category: 'Tests-Morphic-Scripting'
> 
> 
> Ok. the "button" instVar will hold a button instance, nicely accessible
> so we can probe it as we want.
> 
> This button need to be set up befor running a test, and killed
> afterwards. So we add two methods:
> 
> setUp
> 
> 	button := ScriptableButton new openInWorld.
> 
> tearDown
> 
> 	button delete.
> 
> Ok. Now the button is ready for testing. Browsing the class 
> "ScriptableButton" we find out pretty quickly which method gets
> called when we press that <strangecolor> Halo: #editButtonsScript
> 
> So we would like to just press this and get no Error. 
> 
> testEditButtonsScript
> 	self shouldnt: [button editButtonsScript] raise: Error.
> 
> That's it. Now we can run the test, and it will fail.
> 
> After filing in Yohikies Bugfix, we will see that for a non-failing
> test we need to do some more cleanup: The script-editing window is
> attached to the Mouse-coursor. So we add some code to kill that window:
> 
> testEditButtonsScript
> 	self shouldnt: [button editButtonsScript] raise: Error.
> 	World currentHand submorphsReverseDo: [:each | each delete].
> 			
> 
> That's it. Now we can make a changeset, sent it to the list with
> "[TEST]" in the subject, and it will be added to the testsuite.
> 
>      Marcus
> 
> 
> -- 
> Marcus Denker marcus at ira.uka.de  -- Squeak! http://squeak.de



More information about the Squeak-dev mailing list