View this PageEdit this PageAttachments to this PageHistory of this PageHomeRecent ChangesSearch the SwikiHelp Guide
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
  1. Your code has no syntax errors (if not, the SUnit testing returns an error)
  2. Your code has no logic errors (if not, it returns a failure)

But how do you create SUnit testing? It's really quite simple!
  1. Within your package, create a class (you may want to postfix it with "SUnit" or "Test" to make it distinguished)
    1. Make sure that your class's superclass is XProgramming.SUnit.TestCase
    2. Make plenty of instance variables. In our Hospital Management system, we had created 8 Users, 5 Treatments, 5 Patients, etc.
    3. Make the instance variables easily understandable. For example, xNurseA, xNurseB, xDoctorA, etc.
  2. 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.

    1. Make sure to use NO methods for this, as they may be broken.
  1. Create multiple protocols, preferably one for each class that you want to test.
  2. Within each protocol, create a method for each method you want to test.
    1. Make sure to prefix each method you create with "test".
    2. If you are testing adding and removing, test both methods separately.
  3. Design your test
    1. self assert: "conditional statement" checks to make sure the statement is true.
    2. self deny: "conditional statement" checks to make sure the statement is false.
    3. 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.

  1. To run the SUnit tests, go into Workspace and type "TestRunner open" and then hit Ctrl-P
  2. Select your class and hit "Run"
    1. If you get a green bar, congratulations!
    2. 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