Squeak
  links to this page:    
View this PageEdit this Page (locked)Uploads to this PageHistory of this PageTop of the SwikiRecent ChangesSearch the SwikiHelp Guide
How to set up SUnit Tests so they can be run without a GUI
Last updated at 4:32 pm UTC on 14 January 2006
Stephane Ducasse on March 04, 2004
I really appreciate people that submit SUnit tests. You are great! I'm learning a lot reading your tests:) and this is so cool to run the tests and get a green bar.

Now my point: In squeak we do not have yet (in the harvester image :) a way to run SUnit tests without SUnit runner interaction. A trick that I use often while writing SUnit tests is to add "self run: #..." as a comment This way I can while browsing the class execute the test without any UI. For example:
testPeekerUnhibernateBug
	"
       self run: #testPeekerUnhibernateBug
       "
	| bitBlt |
	bitBlt := BitBlt bitPeekerFromForm: Display.
	bitBlt destForm hibernate.
	self shouldnt:[bitBlt pixelAt: 1@1] raise: Error.
This works only in browser. So we could have BitBltTest
testPeekerUnhibernateBug
	"
       BitBltTest run: #testPeekerUnhibernateBug
       "
	| bitBlt |
	bitBlt := BitBlt bitPeekerFromForm: Display.
	bitBlt destForm hibernate.
	self shouldnt:[bitBlt pixelAt: 1@1] raise: Error.
Which results in–> 1 run, 1 passed, 0 failed, 0 errors

Are wondering why we use a three line comment? Why not?
       "BitBltTest run: #testPeekerUnhibernateBug"
It just makes running the test easier. By double clicking on the begining of the line, we can select the line and then do a alt-p to print it.



Annotation: It's better to use "self run: #testSelector" in the comment. If the class is renamed it will still work. If you evaluate it in the context of a browser "self" points to the currently selected class. (tbn)