@@ -26,7 +26,11 @@ public typealias XCTestCaseEntry = (testCaseClass: XCTestCase.Type, allTests: [(
26
26
27
27
public class XCTestCase {
28
28
29
- public required init ( ) {
29
+ /// The name of the test case, consisting of its class name and the method name it will run
30
+ public let name : String
31
+
32
+ public required init ( methodName: String ) {
33
+ name = " \( self . dynamicType) . \( methodName) "
30
34
}
31
35
32
36
public func setUp( ) {
@@ -72,25 +76,33 @@ extension XCTestCase {
72
76
}
73
77
74
78
internal static func invokeTests( tests: [ ( String , XCTestCase throws -> Void ) ] ) {
79
+ let observationCenter = XCTestObservationCenter . sharedTestObservationCenter ( )
80
+
75
81
var totalDuration = 0.0
76
82
var totalFailures = 0
77
83
var unexpectedFailures = 0
78
84
let overallDuration = measureTimeExecutingBlock {
79
85
for (name, test) in tests {
80
- let testCase = self . init ( )
81
- let fullName = " \( testCase. dynamicType) . \( name) "
86
+ let testCase = self . init ( methodName: name)
82
87
83
88
var failures = [ XCTFailure] ( )
84
89
XCTFailureHandler = { failure in
90
+ observationCenter. testCase ( testCase,
91
+ didFailWithDescription: " \( failure. failureDescription) - \( failure. message) " ,
92
+ inFile: failure. file. stringValue,
93
+ atLine: failure. line)
94
+
85
95
if !testCase. continueAfterFailure {
86
- failure. emit ( fullName )
96
+ failure. emit ( testCase . name )
87
97
fatalError ( " Terminating execution due to test failure " , file: failure. file, line: failure. line)
88
98
} else {
89
99
failures. append ( failure)
90
100
}
91
101
}
92
102
93
- XCTPrint ( " Test Case ' \( fullName) ' started. " )
103
+ XCTPrint ( " Test Case ' \( testCase. name) ' started. " )
104
+
105
+ observationCenter. testCaseWillStart ( testCase)
94
106
95
107
testCase. setUp ( )
96
108
@@ -107,20 +119,22 @@ extension XCTestCase {
107
119
testCase. failIfExpectationsNotWaitedFor ( XCTAllExpectations)
108
120
XCTAllExpectations = [ ]
109
121
122
+ observationCenter. testCaseDidFinish ( testCase)
123
+
110
124
totalDuration += duration
111
125
112
126
var result = " passed "
113
127
for failure in failures {
114
- failure. emit ( fullName )
128
+ failure. emit ( testCase . name )
115
129
totalFailures += 1
116
130
if !failure. expected {
117
131
unexpectedFailures += 1
118
132
}
119
133
result = failures. count > 0 ? " failed " : " passed "
120
134
}
121
135
122
- XCTPrint ( " Test Case ' \( fullName ) ' \( result) ( \( printableStringForTimeInterval ( duration) ) seconds). " )
123
- XCTAllRuns . append ( XCTRun ( duration: duration, method: fullName , passed: failures. count == 0 , failures: failures) )
136
+ XCTPrint ( " Test Case ' \( testCase . name ) ' \( result) ( \( printableStringForTimeInterval ( duration) ) seconds). " )
137
+ XCTAllRuns . append ( XCTRun ( duration: duration, method: testCase . name , passed: failures. count == 0 , failures: failures) )
124
138
XCTFailureHandler = nil
125
139
}
126
140
}
0 commit comments