Testing
Framework
Description
This library presents a framework that may be used as the basis for testing
any object's behavior in Smalltalk. The framework permits developers to
create a test case as a class with tests coded in Smalltalk. It simplifies
result checking by recording go/no go statistics and by logging unexpected
exceptions or test failures. Failed cases may be later recreated for debugging.
An interface allows the user to initiate tests, read a summary, then select
and debug failed cases. No script is needed to perform tests. Tests are
initiated for each class found as a subclass of TestCase.
Files
SUnit.pkg
SUnit.sll
SUnit.st |
Testing framework in alternate forms |
| TestDate.cls |
Demo test class to test Date compliance |
Requirements
Visual Smalltalk/Visual Smalltalk Enterprise 3.1.2.
Installation
This library is available in Team/V package form, as an SLL, or as a source
file-in. Select File-Install from the Visual Smalltalk menu bar
and select either SUnit.sll or SUnit.st for installation.
Examples
An example class that uses the framework to test Date compliance has been
included. Select File-Install from the Visual Smalltalk menu bar
and install the file TestDate.cls or evaluate the expression below:
(File pathNameReadOnly:'TestDate.cls') fileIn; close.
This file-in requires the VS/VSE 3.1.2c patch to be applied. If the patch
has not been applied this class will still demonstrate the test framework
but several of the TestDate tests will fail.
The TestDate class tests a Date instance about a given day
span. Both the day and interval use an integer representing the number
of days since Jan 1, 1901 and are set using class methods (this data is
needed for the test case and its need is not specific to the test framework).
Evaluate the following methods to set the test case to use a sample span
and day.
TestDate daySpan:(36000 to:36200). "Jul 26, 1999 to Feb 11, 2000"
TestDate dayCount: 36100. "Nov 3, 1999"
Open the test framework user interface by evaluating:
Press the 'Run' button to start the tests. Tests will be performed for
each class subclassed from TestCase. A more complete test for dates throughout
the day span may be performed by evaluating:
"Test dates throughout the day span"
| suite result testInterface |
suite := TestSuite new.
TestDate daySpan
do:[:day| TestDate dayCount: day.
suite addTest: TestDate suite].
result := suite run.
testInterface := TestRunner new.
testInterface open.
testInterface
displayPassFail: result;
displayDetails: result;
displayDefects: result.
To see what results may look like when a test fails uncomment the line
self assert: date1 = Date fromString: date1 printString.
in method #testShortDateCreation. This assertion may fail because Dates
by default are printed with 2 digit year strings and creation of a Date
from this string is insufficent to assure the century is interpreted correctly.
Test failures or errors will be displayed in the drop down list in the
TestRunner window. Selecting a test from this list will bring up a debug
window on the test case.
The class TestTest serves as a demo and self check for the testing framework.
Additional info
In general, to create a test case create it as a class whose superclass
is TestCase. To this class add methods named by the prefix "test" to identify
it as a method the framework should find and perform tests on. In these
methods setup the objects to be tested and use methods #assert:, #deny:,
#should:, or #shouldnt: to test assertions on the objects. For example,
all the following assertions would produce a failure for the test method
they appear in
self assert: 5 < 3.
self deny: 5 > 3.
self should:[5 < 3].
self shouldnt:[5 > 3].
If an unhandled exception occurs in the method the test case will be logged
as erred.
See the class comments in the framework for a description of each class
function. For the philosophy behind this framework and an example see http://www.armaties.com/testfram.htm.
Contact
Kent Beck
First Class Software
KentBeck@compuserve.com
Links to:
The
ObjectShare web site
VisualSmalltalk
Product Support
ObjectShare's
Online Documentation Site