TestCaseWithArguments.st
author Claus Gittinger <cg@exept.de>
Sat, 30 Jul 2011 10:11:14 +0200
changeset 264 aa6c9be711f5
parent 222 8e6f482297fa
child 269 5ed25f778620
permissions -rw-r--r--
remember execution time (needed to generate prober reports)

"{ Package: 'stx:goodies/sunit' }"

TestCase subclass:#TestCaseWithArguments
	instanceVariableNames:'testArguments'
	classVariableNames:''
	poolDictionaries:''
	category:'SUnit-Base'
!

!TestCaseWithArguments class methodsFor:'documentation'!

documentation
"
    allows for an argument to be passed to the testCase-method.

    To do so, redefine buildAdditionalTestsInSuite:suite,
    to add more tests by sending
	addTest:(self testSelector: testArguments )

    Useful, if you want to evaluate a suites-test method on each file in some directory,
    but still want to see the results as individual runs (to allow for a rerun-defects)

    [author:]
	cg@exept.de
"
! !

!TestCaseWithArguments class methodsFor:'instance creation'!

selector: aSymbol argument: arg
	^self new
	    setTestSelector: aSymbol
	    setTestArguments: (Array with:arg)
!

selector: aSymbol arguments: args
	^self new
	    setTestSelector: aSymbol
	    setTestArguments: args
! !

!TestCaseWithArguments class methodsFor:'building suites'!

buildAdditionalTestsInSuite:suite
    self subclassResponsibility
!

buildSuite
    |suite|

    suite := super buildSuite.
    self buildAdditionalTestsInSuite:suite.
    ^ suite
! !

!TestCaseWithArguments class methodsFor:'testing'!

isAbstract
    "Override to true if a TestCase subclass is Abstract and should not have
     TestCase instances built from it"

    ^ self == TestCaseWithArguments
! !

!TestCaseWithArguments methodsFor:'printing'!

getTestName
    testArguments isEmptyOrNil ifTrue:[^testSelector].
    ^testSelector , '(' , testArguments first printString , ')'.
!

printOn: aStream
	aStream nextPutAll: self name.
	aStream nextPutAll: '>>'.
	testSelector printOn: aStream.
	testSelector numArgs > 0 ifTrue:[
	    aStream nextPutAll: ' ('.
	    testArguments printOn: aStream.
	    aStream nextPutAll: ')'.
	].
! !

!TestCaseWithArguments methodsFor:'private'!

performTest
    startTime := Timestamp now.
    [
        self perform:(testSelector asSymbol) withArguments:(testArguments)
    ] ensure:[
        endTime := Timestamp now
    ].

    "Modified: / 30-07-2011 / 10:09:20 / cg"
!

setTestSelector:aSymbol setTestArguments: args
    testSelector := aSymbol.
    testArguments := args
! !

!TestCaseWithArguments class methodsFor:'documentation'!

version
    ^ '$Header: /cvs/stx/stx/goodies/sunit/TestCaseWithArguments.st,v 1.6 2011-07-30 08:11:14 cg Exp $'
!

version_CVS
    ^ '$Header: /cvs/stx/stx/goodies/sunit/TestCaseWithArguments.st,v 1.6 2011-07-30 08:11:14 cg Exp $'
!

version_SVN
    ^ '§Id: TestCaseWithArguments.st 182 2009-12-05 18:12:17Z vranyj1 §'
! !