Hotspots: Admin Pages | Turn-in Site |
Current Links: Cases Final Project Summer 2007
Discussion 4 - Alex Groleau
What is SUnit and how is it used?
Description: SUnit is a simple testing framework that allows you to test any method of any class. This means that during development and all the way to final testing you can make sure that your taylor polynomial function actually returns the correct result or your Blackjack card algorithm distributes the proper winnings (for example). SUnit will run its tests and tell you clearly which methods are failing.
1. First subclass the TestCase class...
TestCase subclass: #PowerTest
instanceVariables: 'value1 value 2 result1 result2'
category: 'My SUnit Tests'
This example will test my Power class that has the simple method pow.
2. Define the setUp method to instantiate your class and predefine things...
myPower := Power new.
value1 := 5.
value2 := -0.4.
result1 := myPower powa: value1 powb: 4.
result1 := myPower powa: value1 powb: 2.
3. Make some tests (one test per method) in the following way...
self assert: (result1 = 625).
self assert: (result2 = 0.16).
4. Other testing capabilities are...
self deny: - state that the following is not true
self should: raise: Error - says that what is passed into should will raise an error.
self shouldnt: raise: Error - says that what is passed into should will NOT raise an error.
5. To run your tests simply type (in workspace)...
6. There are also TestSuites available for running multiple test classes.
See more information here -> http://scgwiki.iam.unibe.ch:8080/ST2002/uploads/1/SUnit-V1.pdf
Link to this Page