TestResource.st
author Claus Gittinger <cg@exept.de>
Wed, 04 May 2016 21:13:44 +0200
changeset 652 771369120c8b
parent 638 51b8edf986fc
child 667 e2d8d0ff307c
permissions -rw-r--r--
#DOCUMENTATION by cg class: TestResource category of: #version_CVS
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
44
63d3c94197da initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     1
"{ Package: 'stx:goodies/sunit' }"
63d3c94197da initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     2
638
51b8edf986fc class: RBAbstractClass
Claus Gittinger <cg@exept.de>
parents: 590
diff changeset
     3
"{ NameSpace: Smalltalk }"
51b8edf986fc class: RBAbstractClass
Claus Gittinger <cg@exept.de>
parents: 590
diff changeset
     4
222
8e6f482297fa Jan's 4.1 version
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
     5
TestAsserter subclass:#TestResource
44
63d3c94197da initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     6
	instanceVariableNames:'name description'
63d3c94197da initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     7
	classVariableNames:''
63d3c94197da initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     8
	poolDictionaries:''
63d3c94197da initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     9
	category:'SUnit-Base'
63d3c94197da initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    10
!
63d3c94197da initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    11
63d3c94197da initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    12
TestResource class instanceVariableNames:'current'
63d3c94197da initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    13
63d3c94197da initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    14
"
63d3c94197da initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    15
 No other class instance variables are inherited by this class.
63d3c94197da initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    16
"
63d3c94197da initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    17
!
63d3c94197da initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    18
222
8e6f482297fa Jan's 4.1 version
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
    19
TestResource comment:'Normally a test will set up all the objects it needs and tear them down again after it has run.  This self-containedness makes a test more robust.  Use TestResources only for objects that are needed by several tests and that are too ''expensive'' (in time or otherwise) to recreate and destroy for each test.  A viable approach is to develop the code in MyTestCase''s #setUp and #tearDown methods, then at some point refactor the code into the #setUp and #tearDown of a TestResource whose class is added to MyTestCase class>>resource method.
8e6f482297fa Jan's 4.1 version
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
    20
8e6f482297fa Jan's 4.1 version
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
    21
TestResource uses the singleton pattern.  A TestResource class will set up a single instance of itself when first requested and tear it down again at the end of TestSuite>>run (or TestCase>>run, >>debug and >>debugAsFailure).  Normally, a TestResource, once setUp, remains active during the running of all remaining tests and is #reset after all tests have run.  For an exception, see subclass CompetingResource in SUnitResourcePatterns.  Users can choose to #reset a resource in the #tearDown of a test that alters it, sacrificing the performance gain of having a single #setUp of the resource for the certainty that other tests using it will not see the alterations.  Generally however, this should be the exception:  if you need to reset the resource for every test that uses it, its code should just be part of your test''s #setUp and #tearDown code.
8e6f482297fa Jan's 4.1 version
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
    22
8e6f482297fa Jan's 4.1 version
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
    23
To use, create a subclass of TestResource and override the following:
8e6f482297fa Jan's 4.1 version
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
    24
	- TestCase class>>resources, to return a collection including the TestResource class, for all test case classes that need it
8e6f482297fa Jan's 4.1 version
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
    25
		* a TestCase'' resources are set up in the order returned and torn down in the reverse order
8e6f482297fa Jan's 4.1 version
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
    26
	- TestResource class>>resources, if the resource itself always needs some other resource to be present before it can set up
8e6f482297fa Jan's 4.1 version
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
    27
		* a TestResource''s resource are set up before it and torn down after it, and are set up in the order returned and torn down in the reverse order
8e6f482297fa Jan's 4.1 version
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
    28
	- TestResource>>setUp and tearDown, to define initial and final behaviour (just like a test)
8e6f482297fa Jan's 4.1 version
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
    29
	- TestResource>>isAvailable, to return true if it is and false if it isn''t (the framework calls this after setUp);  ideally, this call should not change the resource'' state - that should be done in setUp
8e6f482297fa Jan's 4.1 version
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
    30
8e6f482297fa Jan's 4.1 version
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
    31
TestResource implements the singleton pattern in its class-side #isAvailable and #reset methods.  Do not override these when creating specific resources;  unless you are developing a whole new pattern of use, it will always be correct to override instance-side #setUp, #tearDown and #isAvailable, and dangerous to override class>>isAvailable, class>>isAlreadyAvailable and class>>reset.
8e6f482297fa Jan's 4.1 version
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
    32
8e6f482297fa Jan's 4.1 version
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
    33
Generally, users do not code interactions with a test''s resources during the running of a test.  Code that reads a resource'' values while leaving its state strictly alone is safe enough.  A test must leave a resource in a clean state:  always use #reset if a test must protect later-running tests from unsafe changes (and review whether in such a case a resource is the right thing to use in the first place).
8e6f482297fa Jan's 4.1 version
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
    34
8e6f482297fa Jan's 4.1 version
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
    35
See my superclass'' comment for assertion and logging information.
8e6f482297fa Jan's 4.1 version
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
    36
'
8e6f482297fa Jan's 4.1 version
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
    37
!
8e6f482297fa Jan's 4.1 version
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
    38
8e6f482297fa Jan's 4.1 version
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
    39
8e6f482297fa Jan's 4.1 version
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
    40
!TestResource class methodsFor:'instance creation'!
8e6f482297fa Jan's 4.1 version
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
    41
8e6f482297fa Jan's 4.1 version
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
    42
new
8e6f482297fa Jan's 4.1 version
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
    43
	"Use #current to get the valid current instance.  Use of #new to get an instance (that should never be the current one) could be done in bizarre circumstances, so is not blocked, but will usually be inappropriate."
8e6f482297fa Jan's 4.1 version
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
    44
8e6f482297fa Jan's 4.1 version
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
    45
	^super new initialize
8e6f482297fa Jan's 4.1 version
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
    46
!
8e6f482297fa Jan's 4.1 version
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
    47
8e6f482297fa Jan's 4.1 version
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
    48
reset
8e6f482297fa Jan's 4.1 version
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
    49
	[self isAlreadyAvailable ifTrue: [current tearDown]]
8e6f482297fa Jan's 4.1 version
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
    50
		sunitEnsure: [current := nil].
8e6f482297fa Jan's 4.1 version
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
    51
! !
44
63d3c94197da initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    52
68
9fd111438d60 category renames (lower case)
Claus Gittinger <cg@exept.de>
parents: 44
diff changeset
    53
!TestResource class methodsFor:'accessing'!
44
63d3c94197da initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    54
63d3c94197da initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    55
current
222
8e6f482297fa Jan's 4.1 version
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
    56
	"This is a lazy accessor:  the assert of self isAvailable does no work unless current isNil.  However this method should normally be sent only to a resource that should already have been made available, e.g. in a test whose test case class has the resource class in its #resources, so should never be able to fail the assert.
8e6f482297fa Jan's 4.1 version
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
    57
	If the intent is indeed to access a possibly-unprepared or reset-in-earlier-test resource lazily, then preface the call of 'MyResource current' with 'MyResource availableFor: self'."
103
ad6897ce99e0 Merge SUnit 3.1 changes
Stefan Vogel <sv@exept.de>
parents: 70
diff changeset
    58
222
8e6f482297fa Jan's 4.1 version
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
    59
	self assert: self isAvailable
8e6f482297fa Jan's 4.1 version
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
    60
		description: 'Sent #current to unavailable resource ', self name, '.  Add it to test case'' class-side #resources (recommended) or send #availableFor: beforehand'.
44
63d3c94197da initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    61
	^current
63d3c94197da initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    62
!
63d3c94197da initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    63
103
ad6897ce99e0 Merge SUnit 3.1 changes
Stefan Vogel <sv@exept.de>
parents: 70
diff changeset
    64
resources
ad6897ce99e0 Merge SUnit 3.1 changes
Stefan Vogel <sv@exept.de>
parents: 70
diff changeset
    65
	^#()
44
63d3c94197da initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    66
! !
63d3c94197da initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    67
68
9fd111438d60 category renames (lower case)
Claus Gittinger <cg@exept.de>
parents: 44
diff changeset
    68
!TestResource class methodsFor:'creation'!
44
63d3c94197da initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    69
222
8e6f482297fa Jan's 4.1 version
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
    70
signalInitializationError
8e6f482297fa Jan's 4.1 version
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
    71
	^TestResult signalErrorWith: 'Resource ' , self name , ' could not be initialized'
8e6f482297fa Jan's 4.1 version
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
    72
8e6f482297fa Jan's 4.1 version
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
    73
! !
8e6f482297fa Jan's 4.1 version
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
    74
8e6f482297fa Jan's 4.1 version
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
    75
!TestResource class methodsFor:'private'!
103
ad6897ce99e0 Merge SUnit 3.1 changes
Stefan Vogel <sv@exept.de>
parents: 70
diff changeset
    76
222
8e6f482297fa Jan's 4.1 version
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
    77
makeAvailable
569
edb941b33667 class: TestResource
Claus Gittinger <cg@exept.de>
parents: 448
diff changeset
    78
    "This method must be the _only_ way to set a notNil value for the unique instance (current).  First, obtain a candidate instance and set current to a notNil placeholder (any notNil object not an instance of me would do;  this version uses false).  Next, check any subordinate resources needed by this resource.  Lastly, setUp the candidate and put it in current if it is available, ensuring that it is torn down otherwise."
edb941b33667 class: TestResource
Claus Gittinger <cg@exept.de>
parents: 448
diff changeset
    79
    
edb941b33667 class: TestResource
Claus Gittinger <cg@exept.de>
parents: 448
diff changeset
    80
    |candidate didSetup|
222
8e6f482297fa Jan's 4.1 version
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
    81
569
edb941b33667 class: TestResource
Claus Gittinger <cg@exept.de>
parents: 448
diff changeset
    82
    current := false.
edb941b33667 class: TestResource
Claus Gittinger <cg@exept.de>
parents: 448
diff changeset
    83
    candidate := self new.
edb941b33667 class: TestResource
Claus Gittinger <cg@exept.de>
parents: 448
diff changeset
    84
    self resources do:[:each | 
edb941b33667 class: TestResource
Claus Gittinger <cg@exept.de>
parents: 448
diff changeset
    85
        each availableFor:candidate
edb941b33667 class: TestResource
Claus Gittinger <cg@exept.de>
parents: 448
diff changeset
    86
    ].
edb941b33667 class: TestResource
Claus Gittinger <cg@exept.de>
parents: 448
diff changeset
    87
    [
edb941b33667 class: TestResource
Claus Gittinger <cg@exept.de>
parents: 448
diff changeset
    88
        didSetup := false.
edb941b33667 class: TestResource
Claus Gittinger <cg@exept.de>
parents: 448
diff changeset
    89
        candidate setUp.
590
c13008404767 Fixed copy-paste bug in TestResource>>makeAvailable
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 577
diff changeset
    90
        didSetup := true.
569
edb941b33667 class: TestResource
Claus Gittinger <cg@exept.de>
parents: 448
diff changeset
    91
        candidate isAvailable ifTrue:[
edb941b33667 class: TestResource
Claus Gittinger <cg@exept.de>
parents: 448
diff changeset
    92
            current := candidate
edb941b33667 class: TestResource
Claus Gittinger <cg@exept.de>
parents: 448
diff changeset
    93
        ]
edb941b33667 class: TestResource
Claus Gittinger <cg@exept.de>
parents: 448
diff changeset
    94
    ] sunitEnsure:[
edb941b33667 class: TestResource
Claus Gittinger <cg@exept.de>
parents: 448
diff changeset
    95
        didSetup ifTrue:[
edb941b33667 class: TestResource
Claus Gittinger <cg@exept.de>
parents: 448
diff changeset
    96
            current == candidate ifFalse:[
577
3dea1e941af7 class: TestResource
Stefan Vogel <sv@exept.de>
parents: 569
diff changeset
    97
                candidate safeTearDown
569
edb941b33667 class: TestResource
Claus Gittinger <cg@exept.de>
parents: 448
diff changeset
    98
            ]
edb941b33667 class: TestResource
Claus Gittinger <cg@exept.de>
parents: 448
diff changeset
    99
        ]
edb941b33667 class: TestResource
Claus Gittinger <cg@exept.de>
parents: 448
diff changeset
   100
    ].
590
c13008404767 Fixed copy-paste bug in TestResource>>makeAvailable
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 577
diff changeset
   101
c13008404767 Fixed copy-paste bug in TestResource>>makeAvailable
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 577
diff changeset
   102
    "Modified: / 04-06-2014 / 12:39:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
44
63d3c94197da initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   103
!
63d3c94197da initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   104
222
8e6f482297fa Jan's 4.1 version
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
   105
resetOrAddResourcesTo: aCollection
8e6f482297fa Jan's 4.1 version
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
   106
	"Add correctly set-up resources to the collection unless already there. Reset any imperfectly-set-up resources, so current isNil will return true if they are re-encountered via an indirectly self-prerequing resource;  circular references cannot be set up so will never reply true to isAlreadyAvailable, but may have correctly-set-up prereqs to add and/or imperfectly-set-up ones to reset, so do not abort the loop first time round."
70
2ff4508f476d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 68
diff changeset
   107
222
8e6f482297fa Jan's 4.1 version
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
   108
	current isNil ifTrue: [^self].
8e6f482297fa Jan's 4.1 version
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
   109
	self isAlreadyAvailable
8e6f482297fa Jan's 4.1 version
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
   110
		ifFalse:
8e6f482297fa Jan's 4.1 version
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
   111
			[self reset.
8e6f482297fa Jan's 4.1 version
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
   112
			self resources do: [:each | each resetOrAddResourcesTo: aCollection]]
8e6f482297fa Jan's 4.1 version
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
   113
		ifTrue:
8e6f482297fa Jan's 4.1 version
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
   114
			[(aCollection includes: self) ifFalse:
8e6f482297fa Jan's 4.1 version
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
   115
				[self resources do: [:each | each resetOrAddResourcesTo: aCollection].
8e6f482297fa Jan's 4.1 version
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
   116
				aCollection add: self]].
8e6f482297fa Jan's 4.1 version
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
   117
8e6f482297fa Jan's 4.1 version
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
   118
"The cloned 'self resources do: ...' line in both blocks is, I think, the best way to write this method so that its logic is clear.  The first loop resets this resource immediately, before traversing its resources;  the second traverses before adding"
8e6f482297fa Jan's 4.1 version
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
   119
! !
8e6f482297fa Jan's 4.1 version
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
   120
638
51b8edf986fc class: RBAbstractClass
Claus Gittinger <cg@exept.de>
parents: 590
diff changeset
   121
!TestResource class methodsFor:'queries'!
51b8edf986fc class: RBAbstractClass
Claus Gittinger <cg@exept.de>
parents: 590
diff changeset
   122
51b8edf986fc class: RBAbstractClass
Claus Gittinger <cg@exept.de>
parents: 590
diff changeset
   123
isAbstract
51b8edf986fc class: RBAbstractClass
Claus Gittinger <cg@exept.de>
parents: 590
diff changeset
   124
	"Override to true if a TestResource subclass is Abstract and should not have
51b8edf986fc class: RBAbstractClass
Claus Gittinger <cg@exept.de>
parents: 590
diff changeset
   125
	TestCase instances built from it"
51b8edf986fc class: RBAbstractClass
Claus Gittinger <cg@exept.de>
parents: 590
diff changeset
   126
51b8edf986fc class: RBAbstractClass
Claus Gittinger <cg@exept.de>
parents: 590
diff changeset
   127
	^ self == TestResource
51b8edf986fc class: RBAbstractClass
Claus Gittinger <cg@exept.de>
parents: 590
diff changeset
   128
! !
51b8edf986fc class: RBAbstractClass
Claus Gittinger <cg@exept.de>
parents: 590
diff changeset
   129
222
8e6f482297fa Jan's 4.1 version
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
   130
!TestResource class methodsFor:'running'!
8e6f482297fa Jan's 4.1 version
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
   131
8e6f482297fa Jan's 4.1 version
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
   132
availableFor: aTestAsserter
8e6f482297fa Jan's 4.1 version
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
   133
	aTestAsserter
8e6f482297fa Jan's 4.1 version
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
   134
		assert: self isAvailable
8e6f482297fa Jan's 4.1 version
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
   135
		description: 'Unavailable resource ' , self name , ' requested by ', aTestAsserter printString.
103
ad6897ce99e0 Merge SUnit 3.1 changes
Stefan Vogel <sv@exept.de>
parents: 70
diff changeset
   136
!
ad6897ce99e0 Merge SUnit 3.1 changes
Stefan Vogel <sv@exept.de>
parents: 70
diff changeset
   137
222
8e6f482297fa Jan's 4.1 version
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
   138
resetResources: topLevelResources
8e6f482297fa Jan's 4.1 version
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
   139
	"Reset all imperfectly-set-up resources while gathering the rest for ordered resetting."
8e6f482297fa Jan's 4.1 version
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
   140
8e6f482297fa Jan's 4.1 version
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
   141
	| availableResources |
8e6f482297fa Jan's 4.1 version
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
   142
	availableResources := OrderedCollection new: topLevelResources size.
8e6f482297fa Jan's 4.1 version
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
   143
	topLevelResources do: [:each | each resetOrAddResourcesTo: availableResources].
8e6f482297fa Jan's 4.1 version
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
   144
	availableResources reverseDo: [:each | each reset].
44
63d3c94197da initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   145
! !
63d3c94197da initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   146
68
9fd111438d60 category renames (lower case)
Claus Gittinger <cg@exept.de>
parents: 44
diff changeset
   147
!TestResource class methodsFor:'testing'!
44
63d3c94197da initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   148
222
8e6f482297fa Jan's 4.1 version
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
   149
isAlreadyAvailable
8e6f482297fa Jan's 4.1 version
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
   150
	^current class == self
44
63d3c94197da initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   151
!
63d3c94197da initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   152
63d3c94197da initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   153
isAvailable
222
8e6f482297fa Jan's 4.1 version
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
   154
	"This is (and must be) a lazy method.  If my current has a value, an attempt to make me available has already been made:  trust its result.  If not, try to make me available."
8e6f482297fa Jan's 4.1 version
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
   155
8e6f482297fa Jan's 4.1 version
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
   156
	current isNil ifTrue: [self makeAvailable].
8e6f482297fa Jan's 4.1 version
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
   157
	^self isAlreadyAvailable
44
63d3c94197da initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   158
!
63d3c94197da initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   159
63d3c94197da initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   160
isUnavailable
103
ad6897ce99e0 Merge SUnit 3.1 changes
Stefan Vogel <sv@exept.de>
parents: 70
diff changeset
   161
44
63d3c94197da initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   162
	^self isAvailable not
222
8e6f482297fa Jan's 4.1 version
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
   163
44
63d3c94197da initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   164
! !
63d3c94197da initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   165
68
9fd111438d60 category renames (lower case)
Claus Gittinger <cg@exept.de>
parents: 44
diff changeset
   166
!TestResource methodsFor:'accessing'!
44
63d3c94197da initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   167
63d3c94197da initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   168
description
103
ad6897ce99e0 Merge SUnit 3.1 changes
Stefan Vogel <sv@exept.de>
parents: 70
diff changeset
   169
ad6897ce99e0 Merge SUnit 3.1 changes
Stefan Vogel <sv@exept.de>
parents: 70
diff changeset
   170
	description isNil
ad6897ce99e0 Merge SUnit 3.1 changes
Stefan Vogel <sv@exept.de>
parents: 70
diff changeset
   171
		ifTrue: [^''].
ad6897ce99e0 Merge SUnit 3.1 changes
Stefan Vogel <sv@exept.de>
parents: 70
diff changeset
   172
44
63d3c94197da initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   173
	^description
63d3c94197da initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   174
!
63d3c94197da initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   175
63d3c94197da initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   176
description: aString
103
ad6897ce99e0 Merge SUnit 3.1 changes
Stefan Vogel <sv@exept.de>
parents: 70
diff changeset
   177
44
63d3c94197da initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   178
	description := aString
63d3c94197da initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   179
!
63d3c94197da initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   180
63d3c94197da initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   181
name
103
ad6897ce99e0 Merge SUnit 3.1 changes
Stefan Vogel <sv@exept.de>
parents: 70
diff changeset
   182
ad6897ce99e0 Merge SUnit 3.1 changes
Stefan Vogel <sv@exept.de>
parents: 70
diff changeset
   183
	name isNil
ad6897ce99e0 Merge SUnit 3.1 changes
Stefan Vogel <sv@exept.de>
parents: 70
diff changeset
   184
		ifTrue: [^self printString].
ad6897ce99e0 Merge SUnit 3.1 changes
Stefan Vogel <sv@exept.de>
parents: 70
diff changeset
   185
44
63d3c94197da initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   186
	^name
63d3c94197da initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   187
!
63d3c94197da initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   188
63d3c94197da initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   189
name: aString
103
ad6897ce99e0 Merge SUnit 3.1 changes
Stefan Vogel <sv@exept.de>
parents: 70
diff changeset
   190
44
63d3c94197da initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   191
	name := aString
103
ad6897ce99e0 Merge SUnit 3.1 changes
Stefan Vogel <sv@exept.de>
parents: 70
diff changeset
   192
!
ad6897ce99e0 Merge SUnit 3.1 changes
Stefan Vogel <sv@exept.de>
parents: 70
diff changeset
   193
ad6897ce99e0 Merge SUnit 3.1 changes
Stefan Vogel <sv@exept.de>
parents: 70
diff changeset
   194
resources
ad6897ce99e0 Merge SUnit 3.1 changes
Stefan Vogel <sv@exept.de>
parents: 70
diff changeset
   195
	^self class resources
44
63d3c94197da initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   196
! !
63d3c94197da initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   197
222
8e6f482297fa Jan's 4.1 version
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
   198
!TestResource methodsFor:'initialize-release'!
44
63d3c94197da initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   199
63d3c94197da initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   200
initialize
222
8e6f482297fa Jan's 4.1 version
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
   201
	"This method used to call setUp but now does nothing;  setUp is called by the framework at the appropriate point.  Subclasses may override to set the object to its default state."
44
63d3c94197da initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   202
! !
63d3c94197da initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   203
68
9fd111438d60 category renames (lower case)
Claus Gittinger <cg@exept.de>
parents: 44
diff changeset
   204
!TestResource methodsFor:'printing'!
44
63d3c94197da initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   205
63d3c94197da initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   206
printOn: aStream
103
ad6897ce99e0 Merge SUnit 3.1 changes
Stefan Vogel <sv@exept.de>
parents: 70
diff changeset
   207
44
63d3c94197da initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   208
	aStream nextPutAll: self class printString
63d3c94197da initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   209
! !
63d3c94197da initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   210
577
3dea1e941af7 class: TestResource
Stefan Vogel <sv@exept.de>
parents: 569
diff changeset
   211
!TestResource methodsFor:'private'!
3dea1e941af7 class: TestResource
Stefan Vogel <sv@exept.de>
parents: 569
diff changeset
   212
3dea1e941af7 class: TestResource
Stefan Vogel <sv@exept.de>
parents: 569
diff changeset
   213
safeTearDown
3dea1e941af7 class: TestResource
Stefan Vogel <sv@exept.de>
parents: 569
diff changeset
   214
    "Have to handle Abort. When tearDown is called as inside an ensure block after
3dea1e941af7 class: TestResource
Stefan Vogel <sv@exept.de>
parents: 569
diff changeset
   215
     an abort in the debugger of an errornous test case and raises an error with a debugger
3dea1e941af7 class: TestResource
Stefan Vogel <sv@exept.de>
parents: 569
diff changeset
   216
     itself."
3dea1e941af7 class: TestResource
Stefan Vogel <sv@exept.de>
parents: 569
diff changeset
   217
3dea1e941af7 class: TestResource
Stefan Vogel <sv@exept.de>
parents: 569
diff changeset
   218
    AbortOperationRequest handle:[:ex| ] do:[self tearDown].
3dea1e941af7 class: TestResource
Stefan Vogel <sv@exept.de>
parents: 569
diff changeset
   219
! !
3dea1e941af7 class: TestResource
Stefan Vogel <sv@exept.de>
parents: 569
diff changeset
   220
68
9fd111438d60 category renames (lower case)
Claus Gittinger <cg@exept.de>
parents: 44
diff changeset
   221
!TestResource methodsFor:'running'!
44
63d3c94197da initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   222
63d3c94197da initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   223
setUp
222
8e6f482297fa Jan's 4.1 version
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
   224
	"Does nothing. Subclasses should override this to initialize their resource"
103
ad6897ce99e0 Merge SUnit 3.1 changes
Stefan Vogel <sv@exept.de>
parents: 70
diff changeset
   225
!
ad6897ce99e0 Merge SUnit 3.1 changes
Stefan Vogel <sv@exept.de>
parents: 70
diff changeset
   226
ad6897ce99e0 Merge SUnit 3.1 changes
Stefan Vogel <sv@exept.de>
parents: 70
diff changeset
   227
signalInitializationError
ad6897ce99e0 Merge SUnit 3.1 changes
Stefan Vogel <sv@exept.de>
parents: 70
diff changeset
   228
	^self class signalInitializationError
222
8e6f482297fa Jan's 4.1 version
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
   229
44
63d3c94197da initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   230
!
63d3c94197da initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   231
63d3c94197da initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   232
tearDown
222
8e6f482297fa Jan's 4.1 version
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
   233
	"Does nothing. Subclasses should override this to tear down their resource"
44
63d3c94197da initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   234
! !
63d3c94197da initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   235
68
9fd111438d60 category renames (lower case)
Claus Gittinger <cg@exept.de>
parents: 44
diff changeset
   236
!TestResource methodsFor:'testing'!
44
63d3c94197da initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   237
63d3c94197da initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   238
isAvailable
222
8e6f482297fa Jan's 4.1 version
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
   239
	"Override to provide information on the readiness of the resource.  Put state-changing behaviour in setUp and keep this a state-preserving check as far as possible.  Where setUp is guaranteed to provide a valid resource if it completes, there is no need to override this."
8e6f482297fa Jan's 4.1 version
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
   240
44
63d3c94197da initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   241
	^true
63d3c94197da initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   242
!
63d3c94197da initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   243
63d3c94197da initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   244
isUnavailable
103
ad6897ce99e0 Merge SUnit 3.1 changes
Stefan Vogel <sv@exept.de>
parents: 70
diff changeset
   245
	"override to provide information on the
ad6897ce99e0 Merge SUnit 3.1 changes
Stefan Vogel <sv@exept.de>
parents: 70
diff changeset
   246
	readiness of the resource"
222
8e6f482297fa Jan's 4.1 version
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
   247
44
63d3c94197da initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   248
	^self isAvailable not
222
8e6f482297fa Jan's 4.1 version
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
   249
44
63d3c94197da initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   250
! !
63d3c94197da initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   251
63d3c94197da initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   252
!TestResource class methodsFor:'documentation'!
63d3c94197da initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   253
63d3c94197da initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   254
version
638
51b8edf986fc class: RBAbstractClass
Claus Gittinger <cg@exept.de>
parents: 590
diff changeset
   255
    ^ '$Header$'
217
2033d47baf43 changed: #new
Claus Gittinger <cg@exept.de>
parents: 180
diff changeset
   256
!
2033d47baf43 changed: #new
Claus Gittinger <cg@exept.de>
parents: 180
diff changeset
   257
652
771369120c8b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 638
diff changeset
   258
version_CVS
771369120c8b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 638
diff changeset
   259
    ^ '$Header$'
771369120c8b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 638
diff changeset
   260
!
771369120c8b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 638
diff changeset
   261
222
8e6f482297fa Jan's 4.1 version
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
   262
version_SVN
638
51b8edf986fc class: RBAbstractClass
Claus Gittinger <cg@exept.de>
parents: 590
diff changeset
   263
    ^ '$Id$'
44
63d3c94197da initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   264
! !
569
edb941b33667 class: TestResource
Claus Gittinger <cg@exept.de>
parents: 448
diff changeset
   265