






Hotspots: Admin Pages | Turn-in Site |
Current Links: Cases Final Project Summer 2007
Doing SUnits - Chris Forrence
SUnit Testing is one of the best ways to make sure your application is actually working. It checks to make sure that
- Your code has no syntax errors (if not, the SUnit testing returns an error)
- Your code has no logic errors (if not, it returns a failure)
But how do you create SUnit testing? It's really quite simple!
- Within your package, create a class (you may want to postfix it with "SUnit" or "Test" to make it distinguished)
- Make sure that your class's superclass is XProgramming.SUnit.TestCase
- Make plenty of instance variables. In our Hospital Management system, we had created 8 Users, 5 Treatments, 5 Patients, etc.
- Make the instance variables easily understandable. For example, xNurseA, xNurseB, xDoctorA, etc.
- Create a new method called setUp. Within setUp, set your variables up. For example...
xPatientA := Patient new.
xPatientA name: 'Chris'.
xPatientA id: 24747.
xPatientA status: #inpatient.
xPatientA diagnosis: 'Swine Flu'.
xPatientA primaryDoctor: xDoctorA.
- Make sure to use NO methods for this, as they may be broken.
- Create multiple protocols, preferably one for each class that you want to test.
- Within each protocol, create a method for each method you want to test.
- Make sure to prefix each method you create with "test".
- If you are testing adding and removing, test both methods separately.
- Design your test
- self assert: "conditional statement" checks to make sure the statement is true.
- self deny: "conditional statement" checks to make sure the statement is false.
- Note that in the sample below, I check the initial condition before doing anything.
test := HospitalControl new.
self assert: test hospital users size = 0.
self assert: test hospital doctors size = 0.
test hospital addUser: xDoctorA.
self assert: test hospital users size = 1.
self assert: test hospital doctors size = 1.
- To run the SUnit tests, go into Workspace and type "TestRunner open" and then hit Ctrl-P
- Select your class and hit "Run"
- If you get a green bar, congratulations!
- If you got a red bar, it will divide the problems into errors and failures. Debugging will let you see where the issue is.
Links to this Page
- Cases last edited on 30 July 2011 at 2:33 am by r59h132.res.gatech.edu
- Index of Individual Cases last edited on 3 May 2011 at 12:46 pm by r52h48.res.gatech.edu