TestCaseOutcome.st
author Claus Gittinger <cg@exept.de>
Thu, 26 Feb 2015 05:01:33 +0100
changeset 607 8d830a63bfc0
parent 589 b7cd9f791bb1
child 610 756214d7dcca
child 614 3003097506c9
permissions -rw-r--r--
class: TestCase added: #testSelectorsWithLastOutcomes changed: #testSelector:result:
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
360
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
     1
"{ Package: 'stx:goodies/sunit' }"
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
     2
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
     3
Object subclass:#TestCaseOutcome
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
     4
	instanceVariableNames:'testCase result properties'
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
     5
	classVariableNames:''
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
     6
	poolDictionaries:''
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
     7
	category:'SUnit-Base'
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
     8
!
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
     9
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
    10
!TestCaseOutcome class methodsFor:'documentation'!
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
    11
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
    12
documentation
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
    13
"
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
    14
    will keep additional info for a testCase run:
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
    15
        startTime, endTime,
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
    16
        backtrace (if fail or error)
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
    17
        and collectedStdout
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
    18
"
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
    19
! !
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
    20
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
    21
!TestCaseOutcome class methodsFor:'instance creation'!
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
    22
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
    23
forCase: aTestCase
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
    24
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
    25
    ^self new testCase: aTestCase; yourself
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
    26
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
    27
    "Created: / 16-08-2011 / 15:24:56 / Jan Vrany <jan.vrany@fit.cvut.cz>"
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
    28
! !
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
    29
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
    30
!TestCaseOutcome methodsFor:'accessing'!
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
    31
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
    32
collectedOutput
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
    33
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
    34
    ^self propertyAt: #collectedOutput
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
    35
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
    36
    "Modified: / 16-08-2011 / 15:27:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
    37
    "Created: / 16-08-2011 / 18:19:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
    38
!
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
    39
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
    40
collectedOutput: aString
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
    41
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
    42
    ^self propertyAt: #collectedOutput put: aString
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
    43
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
    44
    "Modified: / 16-08-2011 / 15:28:16 / Jan Vrany <jan.vrany@fit.cvut.cz>"
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
    45
    "Created: / 16-08-2011 / 18:19:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
    46
!
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
    47
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
    48
endTime
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
    49
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
    50
    ^self propertyAt: #endTime
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
    51
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
    52
    "Modified: / 16-08-2011 / 15:28:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
    53
!
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
    54
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
    55
endTime: anObject
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
    56
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
    57
    ^self propertyAt: #endTime put: anObject
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
    58
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
    59
    "Modified: / 16-08-2011 / 15:28:57 / Jan Vrany <jan.vrany@fit.cvut.cz>"
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
    60
!
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
    61
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
    62
exceptionDetail
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
    63
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
    64
    ^self propertyAt: #exceptionDetail
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
    65
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
    66
    "Modified: / 16-08-2011 / 15:29:37 / Jan Vrany <jan.vrany@fit.cvut.cz>"
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
    67
!
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
    68
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
    69
exceptionDetail: anObject
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
    70
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
    71
    ^self propertyAt: #exceptionDetail put: anObject
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
    72
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
    73
    "Modified: / 16-08-2011 / 15:29:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
    74
!
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
    75
379
065605384740 added: #executionTime
Claus Gittinger <cg@exept.de>
parents: 360
diff changeset
    76
executionTime
065605384740 added: #executionTime
Claus Gittinger <cg@exept.de>
parents: 360
diff changeset
    77
    "the execution time in millis; nil if not yet executed"
065605384740 added: #executionTime
Claus Gittinger <cg@exept.de>
parents: 360
diff changeset
    78
065605384740 added: #executionTime
Claus Gittinger <cg@exept.de>
parents: 360
diff changeset
    79
    |startTime endTime|
065605384740 added: #executionTime
Claus Gittinger <cg@exept.de>
parents: 360
diff changeset
    80
065605384740 added: #executionTime
Claus Gittinger <cg@exept.de>
parents: 360
diff changeset
    81
    (startTime := self startTime) isNil ifTrue:[
065605384740 added: #executionTime
Claus Gittinger <cg@exept.de>
parents: 360
diff changeset
    82
        "/ not yet executed
065605384740 added: #executionTime
Claus Gittinger <cg@exept.de>
parents: 360
diff changeset
    83
        ^ nil
065605384740 added: #executionTime
Claus Gittinger <cg@exept.de>
parents: 360
diff changeset
    84
    ].
065605384740 added: #executionTime
Claus Gittinger <cg@exept.de>
parents: 360
diff changeset
    85
    (endTime := self endTime) isNil ifTrue:[
065605384740 added: #executionTime
Claus Gittinger <cg@exept.de>
parents: 360
diff changeset
    86
        "/ assume it is still running...
065605384740 added: #executionTime
Claus Gittinger <cg@exept.de>
parents: 360
diff changeset
    87
        endTime := Timestamp now
065605384740 added: #executionTime
Claus Gittinger <cg@exept.de>
parents: 360
diff changeset
    88
    ].
589
b7cd9f791bb1 class: TestCaseOutcome
Claus Gittinger <cg@exept.de>
parents: 488
diff changeset
    89
    ^ (endTime millisecondDeltaFrom:startTime)
379
065605384740 added: #executionTime
Claus Gittinger <cg@exept.de>
parents: 360
diff changeset
    90
065605384740 added: #executionTime
Claus Gittinger <cg@exept.de>
parents: 360
diff changeset
    91
    "Modified (format): / 18-08-2011 / 21:02:28 / cg"
065605384740 added: #executionTime
Claus Gittinger <cg@exept.de>
parents: 360
diff changeset
    92
!
065605384740 added: #executionTime
Claus Gittinger <cg@exept.de>
parents: 360
diff changeset
    93
360
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
    94
propertyAt: aSymbol
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
    95
379
065605384740 added: #executionTime
Claus Gittinger <cg@exept.de>
parents: 360
diff changeset
    96
    ^ self propertyAt: aSymbol ifAbsent: [nil]
360
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
    97
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
    98
    "Created: / 16-08-2011 / 15:26:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
379
065605384740 added: #executionTime
Claus Gittinger <cg@exept.de>
parents: 360
diff changeset
    99
    "Modified: / 18-08-2011 / 21:03:01 / cg"
360
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
   100
!
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
   101
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
   102
propertyAt: aSymbol ifAbsent: aBlock
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
   103
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
   104
    properties isNil ifTrue: [^aBlock value].
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
   105
    ^properties at: aSymbol ifAbsent:aBlock.
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
   106
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
   107
    "Created: / 16-08-2011 / 15:27:00 / Jan Vrany <jan.vrany@fit.cvut.cz>"
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
   108
!
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
   109
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
   110
propertyAt: aSymbol put: anObject
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
   111
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
   112
    properties isNil ifTrue: [properties := Dictionary new].
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
   113
    properties at: aSymbol put: anObject.
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
   114
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
   115
    "Created: / 16-08-2011 / 15:28:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
   116
!
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
   117
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
   118
result
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
   119
    ^ result
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
   120
!
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
   121
419
e2eb2ab5b937 Lost methods
vrany
parents: 379
diff changeset
   122
result:aSymbol
488
53045c5fc90d class: TestCaseOutcome
Claus Gittinger <cg@exept.de>
parents: 419
diff changeset
   123
    ((aSymbol ~= TestResult statePass) 
53045c5fc90d class: TestCaseOutcome
Claus Gittinger <cg@exept.de>
parents: 419
diff changeset
   124
    and:[ aSymbol ~= TestResult stateFail 
53045c5fc90d class: TestCaseOutcome
Claus Gittinger <cg@exept.de>
parents: 419
diff changeset
   125
    and:[ aSymbol ~= TestResult stateError
53045c5fc90d class: TestCaseOutcome
Claus Gittinger <cg@exept.de>
parents: 419
diff changeset
   126
    and:[ aSymbol ~= TestResult stateSkip ]]]) ifTrue:[
419
e2eb2ab5b937 Lost methods
vrany
parents: 379
diff changeset
   127
        self error:'invalid result'.
e2eb2ab5b937 Lost methods
vrany
parents: 379
diff changeset
   128
    ].
e2eb2ab5b937 Lost methods
vrany
parents: 379
diff changeset
   129
    result := aSymbol.
e2eb2ab5b937 Lost methods
vrany
parents: 379
diff changeset
   130
e2eb2ab5b937 Lost methods
vrany
parents: 379
diff changeset
   131
    "Modified: / 20-08-2011 / 12:52:26 / Jan Vrany <jan.vrany@fit.cvut.cz>"
360
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
   132
!
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
   133
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
   134
selector
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
   135
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
   136
    ^testCase selector
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
   137
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
   138
    "Created: / 16-08-2011 / 15:38:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
   139
!
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
   140
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
   141
startTime
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
   142
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
   143
    ^self propertyAt: #startTime
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
   144
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
   145
    "Modified: / 16-08-2011 / 15:29:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
   146
!
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
   147
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
   148
startTime: anObject
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
   149
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
   150
    ^self propertyAt: #startTime put: anObject
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
   151
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
   152
    "Modified: / 16-08-2011 / 15:29:13 / Jan Vrany <jan.vrany@fit.cvut.cz>"
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
   153
!
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
   154
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
   155
testCase
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
   156
    ^ testCase
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
   157
!
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
   158
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
   159
testCase:something
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
   160
    testCase := something.
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
   161
! !
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
   162
419
e2eb2ab5b937 Lost methods
vrany
parents: 379
diff changeset
   163
!TestCaseOutcome methodsFor:'comparing'!
e2eb2ab5b937 Lost methods
vrany
parents: 379
diff changeset
   164
e2eb2ab5b937 Lost methods
vrany
parents: 379
diff changeset
   165
= anotherOutcome
e2eb2ab5b937 Lost methods
vrany
parents: 379
diff changeset
   166
e2eb2ab5b937 Lost methods
vrany
parents: 379
diff changeset
   167
    ^(anotherOutcome isKindOf: self class) 
e2eb2ab5b937 Lost methods
vrany
parents: 379
diff changeset
   168
        and:[self testCase class == anotherOutcome testCase class
e2eb2ab5b937 Lost methods
vrany
parents: 379
diff changeset
   169
            and:[self testCase selector == anotherOutcome testCase selector]].
e2eb2ab5b937 Lost methods
vrany
parents: 379
diff changeset
   170
e2eb2ab5b937 Lost methods
vrany
parents: 379
diff changeset
   171
    "Created: / 20-08-2011 / 14:24:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
e2eb2ab5b937 Lost methods
vrany
parents: 379
diff changeset
   172
!
e2eb2ab5b937 Lost methods
vrany
parents: 379
diff changeset
   173
e2eb2ab5b937 Lost methods
vrany
parents: 379
diff changeset
   174
hash
e2eb2ab5b937 Lost methods
vrany
parents: 379
diff changeset
   175
e2eb2ab5b937 Lost methods
vrany
parents: 379
diff changeset
   176
    ^testCase hash bitXor: result hash
e2eb2ab5b937 Lost methods
vrany
parents: 379
diff changeset
   177
e2eb2ab5b937 Lost methods
vrany
parents: 379
diff changeset
   178
    "Created: / 20-08-2011 / 14:23:26 / Jan Vrany <jan.vrany@fit.cvut.cz>"
e2eb2ab5b937 Lost methods
vrany
parents: 379
diff changeset
   179
! !
e2eb2ab5b937 Lost methods
vrany
parents: 379
diff changeset
   180
589
b7cd9f791bb1 class: TestCaseOutcome
Claus Gittinger <cg@exept.de>
parents: 488
diff changeset
   181
!TestCaseOutcome methodsFor:'printing & storing'!
b7cd9f791bb1 class: TestCaseOutcome
Claus Gittinger <cg@exept.de>
parents: 488
diff changeset
   182
b7cd9f791bb1 class: TestCaseOutcome
Claus Gittinger <cg@exept.de>
parents: 488
diff changeset
   183
printOn:aStream
b7cd9f791bb1 class: TestCaseOutcome
Claus Gittinger <cg@exept.de>
parents: 488
diff changeset
   184
    "append a printed representation if the receiver to the argument, aStream"
b7cd9f791bb1 class: TestCaseOutcome
Claus Gittinger <cg@exept.de>
parents: 488
diff changeset
   185
b7cd9f791bb1 class: TestCaseOutcome
Claus Gittinger <cg@exept.de>
parents: 488
diff changeset
   186
    super printOn:aStream.
b7cd9f791bb1 class: TestCaseOutcome
Claus Gittinger <cg@exept.de>
parents: 488
diff changeset
   187
    aStream nextPut:$(.
b7cd9f791bb1 class: TestCaseOutcome
Claus Gittinger <cg@exept.de>
parents: 488
diff changeset
   188
    testCase printOn: aStream.
b7cd9f791bb1 class: TestCaseOutcome
Claus Gittinger <cg@exept.de>
parents: 488
diff changeset
   189
    aStream nextPut:$).
b7cd9f791bb1 class: TestCaseOutcome
Claus Gittinger <cg@exept.de>
parents: 488
diff changeset
   190
b7cd9f791bb1 class: TestCaseOutcome
Claus Gittinger <cg@exept.de>
parents: 488
diff changeset
   191
    "Modified: / 17-07-2013 / 17:59:09 / Jan Vrany <jan.vrany@fit.cvut.cz>"
b7cd9f791bb1 class: TestCaseOutcome
Claus Gittinger <cg@exept.de>
parents: 488
diff changeset
   192
! !
b7cd9f791bb1 class: TestCaseOutcome
Claus Gittinger <cg@exept.de>
parents: 488
diff changeset
   193
419
e2eb2ab5b937 Lost methods
vrany
parents: 379
diff changeset
   194
!TestCaseOutcome methodsFor:'remembering'!
e2eb2ab5b937 Lost methods
vrany
parents: 379
diff changeset
   195
e2eb2ab5b937 Lost methods
vrany
parents: 379
diff changeset
   196
remember
e2eb2ab5b937 Lost methods
vrany
parents: 379
diff changeset
   197
e2eb2ab5b937 Lost methods
vrany
parents: 379
diff changeset
   198
    ^testCase class rememberOutcome: self.
e2eb2ab5b937 Lost methods
vrany
parents: 379
diff changeset
   199
e2eb2ab5b937 Lost methods
vrany
parents: 379
diff changeset
   200
    "Created: / 20-08-2011 / 12:45:51 / Jan Vrany <jan.vrany@fit.cvut.cz>"
e2eb2ab5b937 Lost methods
vrany
parents: 379
diff changeset
   201
! !
e2eb2ab5b937 Lost methods
vrany
parents: 379
diff changeset
   202
360
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
   203
!TestCaseOutcome class methodsFor:'documentation'!
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
   204
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
   205
version_CVS
589
b7cd9f791bb1 class: TestCaseOutcome
Claus Gittinger <cg@exept.de>
parents: 488
diff changeset
   206
    ^ '$Header: /cvs/stx/stx/goodies/sunit/TestCaseOutcome.st,v 1.6 2014-04-16 22:06:04 cg Exp $'
360
57c87e624dc6 initial checkin
vrany
parents:
diff changeset
   207
! !
589
b7cd9f791bb1 class: TestCaseOutcome
Claus Gittinger <cg@exept.de>
parents: 488
diff changeset
   208