@@ -31,38 +31,37 @@ extension XCTestCase {
31
31
var totalDuration = 0.0
32
32
var totalFailures = 0
33
33
var unexpectedFailures = 0
34
- for (name, test) in tests {
35
- XCTCurrentTestCase = self
36
- let method = " \( self . dynamicType) . \( name) "
37
- var duration : Double = 0.0
38
- print ( " Test Case ' \( method) ' started. " )
39
-
40
- setUp ( )
41
-
42
- let start = currentTimeIntervalSinceReferenceTime ( )
43
- test ( )
44
- let end = currentTimeIntervalSinceReferenceTime ( )
45
-
46
- tearDown ( )
47
-
48
- duration = end - start
49
- totalDuration += duration
50
- for failure in XCTCurrentFailures {
51
- failure. emit ( method)
52
- totalFailures += 1
53
- if !failure. expected {
54
- unexpectedFailures += 1
34
+ let overallDuration = measureTimeExecutingBlock {
35
+ for (name, test) in tests {
36
+ XCTCurrentTestCase = self
37
+ let method = " \( self . dynamicType) . \( name) "
38
+ print ( " Test Case ' \( method) ' started. " )
39
+
40
+ setUp ( )
41
+
42
+ let duration = measureTimeExecutingBlock ( test)
43
+
44
+ tearDown ( )
45
+
46
+ totalDuration += duration
47
+ for failure in XCTCurrentFailures {
48
+ failure. emit ( method)
49
+ totalFailures += 1
50
+ if !failure. expected {
51
+ unexpectedFailures += 1
52
+ }
55
53
}
54
+ var result = " passed "
55
+ if XCTCurrentFailures . count > 0 {
56
+ result = " failed "
57
+ }
58
+ print ( " Test Case ' \( method) ' \( result) ( \( printableStringForTimeInterval ( duration) ) seconds). " )
59
+ XCTAllRuns . append ( XCTRun ( duration: duration, method: method, passed: XCTCurrentFailures . count == 0 , failures: XCTCurrentFailures) )
60
+ XCTCurrentFailures . removeAll ( )
61
+ XCTCurrentTestCase = nil
56
62
}
57
- var result = " passed "
58
- if XCTCurrentFailures . count > 0 {
59
- result = " failed "
60
- }
61
- print ( " Test Case ' \( method) ' \( result) ( \( printableStringForTimeInterval ( duration) ) seconds). " )
62
- XCTAllRuns . append ( XCTRun ( duration: duration, method: method, passed: XCTCurrentFailures . count == 0 , failures: XCTCurrentFailures) )
63
- XCTCurrentFailures . removeAll ( )
64
- XCTCurrentTestCase = nil
65
63
}
64
+
66
65
var testCountSuffix = " s "
67
66
if tests. count == 1 {
68
67
testCountSuffix = " "
@@ -71,9 +70,8 @@ extension XCTestCase {
71
70
if totalFailures == 1 {
72
71
failureSuffix = " "
73
72
}
74
- let averageDuration = totalDuration / Double( tests. count)
75
-
76
- print ( " Executed \( tests. count) test \( testCountSuffix) , with \( totalFailures) failure \( failureSuffix) ( \( unexpectedFailures) unexpected) in \( printableStringForTimeInterval ( averageDuration) ) ( \( printableStringForTimeInterval ( totalDuration) ) ) seconds " )
73
+
74
+ print ( " Executed \( tests. count) test \( testCountSuffix) , with \( totalFailures) failure \( failureSuffix) ( \( unexpectedFailures) unexpected) in \( printableStringForTimeInterval ( totalDuration) ) ( \( printableStringForTimeInterval ( overallDuration) ) ) seconds " )
77
75
}
78
76
79
77
// This function is for the use of XCTestCase only, but we must make it public or clients will get a link failure when using XCTest (23476006)
0 commit comments