[View]  [Edit]  [Lock]  [References]  [Attachments]  [History]  [Home]  [Changes]  [Search]  [Help] 

sunit[meta] tests

TestCase
   subclass: #SUnitTest
   instanceVariableNames: ''
   category: 'sunit-meta'!

! SUnitTest methodsFor: #private !  
assertForTestResult: aResult 
run: aRunCount 
failed: aFailureCount 
errors: anErrorCount
	
   self
      assert: aResult runs = aRunCount;
      assert: aResult failures size = aFailureCount;
      assert: aResult errors size = anErrorCount ! !
	
! SUnitTest methodsFor: #private ! 
setUp
   Smalltalk at:#CounterSetup put: 0.
   Smalltalk at:#CounterTeardown put: 0! !

! SUnitTest methodsFor: #private ! 
tearDown
   Smalltalk removeKey: #CounterSetup ifAbsent:[].
   Smalltalk removeKey: #CounterTeardown ifAbsent:[]! !	
	
! SUnitTest methodsFor: #private ! 
error
   3 zork! !

! SUnitTest methodsFor: #private ! 
noop
   ! !

! SUnitTest methodsFor: #private ! 
fail
   self assert: false! !

! SUnitTest methodsFor: #testing ! 
testAssert
   self assert: true.
   self deny: false! !

! SUnitTest methodsFor: #testing ! 
testError

   | result |
   result := TestResult new.
   self perform: #error testFor: result doing: nil.
   self 
      assertForTestResult: result
      run: 1
      failed: 0
      errors: 1.! !

! SUnitTest methodsFor: #testing ! 
testFail
	
   | result |
   result := TestResult new.
   self perform: #fail testFor: result doing: nil.
   self 
      assertForTestResult: result
      run: 1
      failed: 1
      errors: 0.! !

! SUnitTest methodsFor: #testing ! 
testResult
   
   | result |
   result := TestResult new.
   self perform: #noop testFor: result doing: nil.
   self
      assertForTestResult: result
      run: 1
      failed: 0
      errors: 0! !

! SUnitTest methodsFor: #testing ! 
testSetupTeardown

   | test |	
   test := SampleTest new.
   TestRunner run: SampleTest.
   self assert: ((CounterSetup = 1) and:[CounterTeardown = 1]) ! !
		
TestCase
   subclass: #SampleTest
   instanceVariableNames: ''
   category: 'sunit-helper'!
SampleTest comment: 'This class only makes sense as helper for SUnitTest. It should never be executed as a single test.'

! SampleTest methodsFor: #running !   
setUp
   CounterSetup:= CounterSetup + 1! !

! SampleTest methodsFor: #running !   
tearDown
   CounterTeardown:= CounterTeardown + 1! !
	
! SampleTest methodsFor: #testing !   
test1
   ! !

! SampleTest methodsFor: #testing !   
test2
   ! !