defined source container
authorStefan Vogel <sv@exept.de>
Fri, 26 Sep 2003 18:08:52 +0200
changeset 109 7bb3f3015dd5
parent 108 7509607479f5
child 110 acc83879849e
defined source container
SUnitTest.st
--- a/SUnitTest.st	Fri Sep 26 18:01:01 2003 +0200
+++ b/SUnitTest.st	Fri Sep 26 18:08:52 2003 +0200
@@ -7,29 +7,25 @@
 	category:'SUnit-Tests'
 !
 
-!SUnitTest class methodsFor:'documentation'!
-
-description
-    ^ 'Tests SUnit itself
-Two tests should fail.'
-! !
+SUnitTest comment:'This is both an example of writing tests and a self test for the SUnit. The tests 
+here are pretty strange, since you want to make sure things blow up. You should 
+not generally have to write tests this complicated in structure, although they 
+will be far more complicated in terms of your own objects- more assertions, more 
+complicated setup. Kent says: "Never forget, however, that if the tests are hard 
+to write, something is probably wrong with the design".'
+!
 
-!SUnitTest class methodsFor:'testing'!
-
-shouldInheritSelectors
-	"answer true to inherit selectors from superclasses"
-
-	^false
-! !
 
 !SUnitTest methodsFor:'accessing'!
 
 hasRun
 	^hasRun
+			
 !
 
 hasSetup
 	^hasSetup
+			
 ! !
 
 !SUnitTest methodsFor:'private'!
@@ -41,44 +37,47 @@
 		assert: aResult passedCount = aPassedCount;
 		assert: aResult failureCount = aFailureCount;
 		assert: aResult errorCount = anErrorCount
+			
 !
 
 error
 	3 zork
-
-    "Modified: / 21.6.2000 / 10:22:18 / Sames"
+			
 !
 
 fail
-        "force a failure"
-        self assert: false
+	self assert: false
+			
 !
 
 noop
+			
 !
 
 setRun
 	hasRun := true
+			
 ! !
 
 !SUnitTest methodsFor:'running'!
 
 setUp
 	hasSetup := true
+			
 ! !
 
 !SUnitTest methodsFor:'testing'!
 
+errorShouldntRaise
+        self 
+                shouldnt: [self someMessageThatIsntUnderstood] 
+                raise: SUnitNameResolver notificationObject
+!
+
 testAssert
 	self assert: true.
 	self deny: false
-!
-
-testDebugUI
-	"This should break"
-	3 zork
-
-    "Modified: / 21.6.2000 / 10:22:50 / Sames"
+			
 !
 
 testDefects
@@ -94,18 +93,25 @@
 		passed: 0
 		failed: 1
 		errors: 1
+			
 !
 
 testDialectLocalizedException
-	self should: [TestResult signalFailureWith: 'Foo'] raise: TestResult failure.
-	self should: [TestResult signalErrorWith: 'Foo'] raise: TestResult error.
-	self shouldnt: [TestResult signalErrorWith: 'Foo'] raise: TestResult failure.
 
-    "Modified: / 21.6.2000 / 10:23:20 / Sames"
+	self
+		should: [TestResult signalFailureWith: 'Foo']
+		raise: TestResult failure.
+	self
+		should: [TestResult signalErrorWith: 'Foo']
+		raise: TestResult error.
+
+			
 !
 
 testError
+
 	| case result |
+
 	case := self class selector: #error.
 	result := case run.
 	self
@@ -113,92 +119,123 @@
 		runCount: 1
 		passed: 0
 		failed: 0
+		errors: 1.
+
+	case := self class selector: #errorShouldntRaise.
+	result := case run.
+	self 
+		assertForTestResult: result
+		runCount: 1
+		passed: 0
+		failed: 0
 		errors: 1
+			
 !
 
 testException
-	self should: [self error: 'foo'] raise: TestResult error
 
-    "Modified: / 21.6.2000 / 10:23:39 / Sames"
+	self
+		should: [self error: 'foo']
+		raise: TestResult error
+			
 !
 
 testFail
+
 	| case result |
+
 	case := self class selector: #fail.
 	result := case run.
+
 	self
 		assertForTestResult: result
 		runCount: 1
 		passed: 0
 		failed: 1
 		errors: 0
-!
-
-testFailureDebugUI
-	"This should fail !!"
-	self fail
+			
 !
 
 testIsNotRerunOnDebug
+
 	| case |
+
 	case := self class selector: #testRanOnlyOnce.
 	case run.
 	case debug
+			
 !
 
 testRan
+
 	| case |
+
 	case := self class selector: #setRun.
 	case run.
 	self assert: case hasSetup.
 	self assert: case hasRun
+			
 !
 
 testRanOnlyOnce
+
 	self assert: hasRanOnce ~= true.
-	hasRanOnce := true.
+	hasRanOnce := true
+			
 !
 
 testResult
+
 	| case result |
+
 	case := self class selector: #noop.
 	result := case run.
+
 	self
 		assertForTestResult: result
 		runCount: 1
 		passed: 1
 		failed: 0
 		errors: 0
+			
 !
 
 testRunning
-	(SUnitDelay forSeconds: 2) wait
 
-    "Modified: / 21.6.2000 / 10:24:41 / Sames"
+        (Delay forSeconds: 2) wait
 !
 
 testShould
-	self should: [true].
-	self shouldnt: [false]
+
+	self
+		should: [true];
+		shouldnt: [false]
+			
 !
 
 testSuite
+
 	| suite result |
+
 	suite := TestSuite new.
-	suite addTest: (self class selector: #noop).
-	suite addTest: (self class selector: #fail).
-	suite addTest: (self class selector: #error).
+	suite 
+		addTest: (self class selector: #noop);
+		addTest: (self class selector: #fail);
+		addTest: (self class selector: #error).
+
 	result := suite run.
+
 	self
 		assertForTestResult: result
 		runCount: 3
 		passed: 1
 		failed: 1
 		errors: 1
+			
 ! !
 
 !SUnitTest class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/goodies/sunit/SUnitTest.st,v 1.8 2002-02-26 10:30:34 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/goodies/sunit/SUnitTest.st,v 1.9 2003-09-26 16:08:52 stefan Exp $'
 ! !