links to this page:    
View this PageEdit this PageUploads to this PageHistory of this PageTop of the SwikiRecent ChangesSearch the SwikiHelp Guide
Submitting SUnit tests
Last updated at 7:19 pm UTC on 4 December 2007
On March 2, 2002, Stefan Matthias Aust wrote to the mailing list:

I propose a new official tag for use with squeak-dev: [TEST]. A mail with [TEST] should contain one or more SUnit tests.

[BUG][TEST] –> That's the way to do a really nice bug report.
[BUG][FIX][TEST] –> even better ;-)

All tests that are sent to the list will be included in the BaseImage-test package on SqueakMap after review.

For a nice introduction to Sunit, see:

Below is a post from Marcus Denkker on the squeak-dev list that gives a very simple tutorial on how to write a test for a specific bug (the specific bug might be fixed by the time you read this, but the idea is very clear)

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:


button := ScriptableButton new openInWorld.


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 Halo: #editButtonsScript

So we would like to just press this and get no Error.

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:

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.