1 testing UnitTests addPrototype: #SUnit derivedFrom: {TestCase}.
2 "This is both an example of writing tests and a self test for the SUnit.
3 The tests here are pretty strange, since you want to make sure things don't blow up.
4 You should not generally have to write tests this complicated in structure,
5 although they will be far more complicated in terms of your own objects-
6 more assertions, more complicated setup."
7 UnitTests SUnit addSlot: #hasRun valued: False.
8 UnitTests SUnit addSlot: #hasSetup valued: False.
9 UnitTests SUnit addSlot: #hasRanOnce valued: False.
11 t@(UnitTests SUnit traits) setUp
16 t@(UnitTests SUnit traits) error
19 t@(UnitTests SUnit traits) noop
22 t@(UnitTests SUnit traits) fail
25 t@(UnitTests SUnit traits) setRun
30 t@(UnitTests SUnit traits) assertForTestResult: result runs: ran passed: passed
31 failed: failed errors: broke
33 t assert: result runCount = ran.
34 t assert: result passedCount = passed.
35 t assert: result failureCount = failed.
36 t assert: result errorCount = broke.
39 t@(UnitTests SUnit traits) testAssert
45 t@(UnitTests SUnit traits) testDebugger
46 "Disabled, so that running all tests passes. Uncomment to enable.
47 This test should break."
50 t@(UnitTests SUnit traits) testDefects
51 [| result suite error failure |
53 suite tests include: (error: (t newForSelector: #error)).
54 suite tests include: (failure: (t newForSelector: #fail)).
55 error logErrors: False.
56 failure logErrors: False.
58 t assert: result defects = {error. failure}.
59 t assertForTestResult: result
60 runs: 2 passed: 0 failed: 1 errors: 1.
63 t@(UnitTests SUnit traits) testException
65 t should: [t signalFailureDescription: 'Foo'] raise: TestFailure.
66 t should: [TestResult signalFailureDescription: 'Foo'] raise: Error.
67 t shouldnt: [TestResult signalFailureDescription: 'Foo'] raise: TestFailure.
70 t@(UnitTests SUnit traits) testError
72 case: (t newForSelector: #error).
73 case logErrors: False.
75 t assertForTestResult: result
76 runs: 1 passed: 0 failed: 0 errors: 1.
79 t@(UnitTests SUnit traits) testFail
81 case: (t newForSelector: #fail).
82 case logErrors: False.
84 t assertForTestResult: result
85 runs: 1 passed: 0 failed: 1 errors: 0.
88 t@(UnitTests SUnit traits) testFailDebugger
89 "Disabled, so running all tests passes. Uncomment to enable.
90 This test should fail."
93 t@(UnitTests SUnit traits) testIsNotRerunOnDebug
95 case: (t newForSelector: #testRanOnlyOnce).
97 "case invokeDebugger."
100 t@(UnitTests SUnit traits) testShould
106 t@(UnitTests SUnit traits) testRan
108 case: (t newForSelector: #setRun).
110 t assert: case hasSetup.
111 t assert: case hasRun.
114 t@(UnitTests SUnit traits) testRanOnlyOnce
116 t assert: t hasRanOnce ~= True.
120 t@(UnitTests SUnit traits) testResult
122 case: (t newForSelector: #noop).
124 t assertForTestResult: result
125 runs: 1 passed: 1 failed: 0 errors: 0.
126 "Ensure prototype isn't modified"
127 t assertForTestResult: TestResult
128 runs: 0 passed: 0 failed: 0 errors: 0.
131 t@(UnitTests SUnit traits) suite
132 [t suiteForSelectors: {
136 #testIsNotRerunOnDebug.