Title: Introduction to SUnit and Blackbox Testing
1Introduction to SUnit and Blackbox Testing
2Exception Handling in Squeak
- Class Exception and its subclasses provided for
use. - Can emulate try/catch block in other languages
- Exceptions pass up inheritance hierarchy. If not
handled, get default handler at Object.
3Example
x y x7. y0. x / y on ZeroDivide
do exception Transcript show
exception description cr. 0 .
4Example
f fFileStream fileNamed 'fred'. f
nextPutAll 'Test'. f close. on
FileDoesNotExistException do exception
Transcript show exception description. .
5Blackbox Testing
- Going to get the theory from 2335.
- Treat code as a blackbox
- Base test cases on specification
- Two major techniques
- Equivalence Partitions
- Boundary Tests
- Exhaustive testing not possible
6Equivalence Partititions
- Treat sets of data as same (if one test succeeds
all tests succeed) - For ranges, pick one test in range, one test on
each end. - For sets, pick one in set, one not in set.
- For unique values, pick value, not value.
7Examples
- Must accept years between 1-2050. Test cases 0,
1876 , 2076. - Passwords must be 6-8 chars long
- Test cases ab, abcdef, abcdegujswidn
- Leap years are divisible by four
- Test cases 16, 99
- Phone exchanges must not begin with 555.
- Test cases 555, 498
8Writing your tests
- We could just write workspace code and DoIt over
and over - Hoping that we dont ever close window
- Checking transcript manually to ensure results
are what we want. - We could write a custom class to do our test and
result checking - We can use the SUnit framework.
9SUnit
- We will cover framework in more detail later.
- Learn by rote
- Derive class from TestCase
- Create methods testXxxx
- Use
- self assert expr_that_evals_true
- self deny expr_that_evals_false
- self should block that evals to true .
- self shouldnt block that evals to false .
- TestRunner open.
10Example
Assume we have a class BobO with method name
aName nameaName. name. And name
name.
testName aClass aClass_BobO new. aClass
name 'Bob'. self assert aClass name 'Bob'.
self should aClass name Bob. self deny
aClass name oBb.
TestCase subclass TestBobO
instanceVariableNames classVariableNames
poolDictionaries category Bob
Classes .
11Key steps
- For each real class X, have a test class TestX
derived from TestCase - Decide how to test each method
- For each method y in class X, have a test method
testY in class TestX. - Run TestRunner to evaluate tests automatically
- May use SqueakMap to download TestBrowser if
desired.
12M1 Questions???