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

How to test

How to test:
SUnit when not used properly is a waste of time for the programming team. Proper tests try to break your code. Improper tests look at situations that you know will work. Two types of tests learned during this class are called equivalence partitions and boundary testing. Descriptions of these tests can be found in the lecture slides for SUnit:

Creating Tests using SUnit Test Browser:
To make testing easier and faster, use SUnit test browser. To install the test browser, open up the universe browser, which can be found by clicking on open in the world menu:

Uploaded Image: installation.jpg

After installation, open up the Test Browser by using the following command:

TestBrowser open

or through the open menu.

Now we can create tests! Our first step is to create the class in which we will test. This is done just as it would be done in a regular browser. This time, let’s make the class inherit from TestCase. Proper naming convention directs us to call our test TestCharacterMorph, since we will be testing a CharacterMorph. We now also create an instance variable called aCharacter, which is one of our yet-to-be implemented CharacterMorphs.

Uploaded Image: creation.jpg

The setUp method inside the running category is where we would initialize our aCharacter instance variable so it can be used in our tests.

After initializing the instance variables in setUp, we can now create our tests. Let’s test our character’s movement.
aCharacter x: 0.
aCharacter y: 0.
aCharacter move: 10 direction: 2.
self assert: aCharacter x = 0.
self assert: aCharacter y = 10.
aCharacter move: 10 direction: 6.
self assert: aCharacter x = 6.
self assert: aCharacter y = 10.
aCharacter move: 0 direction: 6.
self assert: aCharacter x = 6.
self assert: aCharacter y = 10.
aCharacter move: 2 direction: 9.
self assert: aCharacter x = 8.
self assert: aCharacter y = 8.

The basic idea of this test is to manipulate our character and then test it to see if it has moved correctly. “self assert” is the actual test. It takes in a Boolean. If it, along with all the other asserts, evaluate to true then the test passes. “self deny” can also be used, in which the test passes if the Boolean expression evaluates to false. Other tests are:

self should: aBlock raise: Exception.
self shouldnt: aBlock raise: Exception.

To more thoroughly test our move method, numbers should be fed in that are invalid or are at the boundary. For example, a negative move amount or zero could be fed in. For direction (which only wants 1-9), we could feed in 1 and 9 (to test boundries) and 0, 6, and 10 (to test partitions). We can then plan the implementation of this method to not respond or give an error message to the invalid input.

Running the tests:
The easiest step! Just press the run category button to run all the tests in the category. The setUp method is called automatically and feedback is given about the tests. Now, our tests give errors due to the fact that CharacterMorph is empty and completely unimplemented. During the course of implementation, the errors will go away and the failed tests will turn into passed tests. The magic of squeak here is that method stubs (such as one for move in CharacterMorph) do not need to be filled out as it would for extreme programming in java.

Now all that is left is to similarly implement tests for all the other important methods. Some tips:

Do not assume that even the simplest method will work! Test everything!
Do not baby your code. Try to beat it to death. Battle-hardened code is better!

Links to this Page