1 testing UnitTests define: #SUnit &parents: {TestCase} &slots: {
6 "This is both an example of writing tests and a self test for the SUnit.
7 The tests here are pretty strange, since you want to make sure things don't blow up.
8 You should not generally have to write tests this complicated in structure,
9 although they will be far more complicated in terms of your own objects-
10 more assertions, more complicated setup."
12 t@(UnitTests SUnit traits) setUp
17 t@(UnitTests SUnit traits) error
20 t@(UnitTests SUnit traits) noop
23 t@(UnitTests SUnit traits) fail
26 t@(UnitTests SUnit traits) setRun
31 t@(UnitTests SUnit traits) assertForTestResult: result runs: ran passed: passed
32 failed: failed errors: broke
34 t assert: result runCount = ran.
35 t assert: result passedCount = passed.
36 t assert: result failureCount = failed.
37 t assert: result errorCount = broke.
40 t@(UnitTests SUnit traits) testAssert
46 t@(UnitTests SUnit traits) testDebugger
47 "Disabled, so that running all tests passes. Uncomment to enable.
48 This test should break."
51 t@(UnitTests SUnit traits) testDefects
53 suite ::= TestSuite new.
54 suite tests include: (error ::= t newForSelector: #error).
55 suite tests include: (failure ::= t newForSelector: #fail).
56 error logErrors := False.
57 failure logErrors := False.
59 t assert: result defects = {error. failure}.
60 t assertForTestResult: result
61 runs: 2 passed: 0 failed: 1 errors: 1.
64 t@(UnitTests SUnit traits) testException
66 t should: [t signalFailureDescription: 'Foo'] raise: TestFailure.
67 t should: [TestResult signalFailureDescription: 'Foo'] raise: Error.
68 t shouldnt: [TestResult signalFailureDescription: 'Foo'] raise: TestFailure.
71 t@(UnitTests SUnit traits) testError
73 case ::= t newForSelector: #error.
74 case logErrors := False.
76 t assertForTestResult: result
77 runs: 1 passed: 0 failed: 0 errors: 1.
80 t@(UnitTests SUnit traits) testFail
82 case ::= t newForSelector: #fail.
83 case logErrors := False.
85 t assertForTestResult: result
86 runs: 1 passed: 0 failed: 1 errors: 0.
89 t@(UnitTests SUnit traits) testFailDebugger
90 "Disabled, so running all tests passes. Uncomment to enable.
91 This test should fail."
94 t@(UnitTests SUnit traits) testIsNotRerunOnDebug
96 case ::= t newForSelector: #testRanOnlyOnce.
98 "case invokeDebugger."
101 t@(UnitTests SUnit traits) testShould
107 t@(UnitTests SUnit traits) testRan
109 case ::= t newForSelector: #setRun.
111 t assert: case hasSetup.
112 t assert: case hasRun.
115 t@(UnitTests SUnit traits) testRanOnlyOnce
117 t assert: t hasRanOnce ~= True.
121 t@(UnitTests SUnit traits) testResult
123 case ::= t newForSelector: #noop.
125 t assertForTestResult: result
126 runs: 1 passed: 1 failed: 0 errors: 0.
127 "Ensure prototype isn't modified"
128 t assertForTestResult: TestResult
129 runs: 0 passed: 0 failed: 0 errors: 0.
132 t@(UnitTests SUnit traits) suite
133 [t suiteForSelectors: {
137 #testIsNotRerunOnDebug.