You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Not everyone wants to be notified of test results in the same way.
Some people prefer a concise view that fits on a single line, with
dots indicating success and "F" to signify failure: ".....FF..F"
Some prefer a detailed view, containing data on how long each test took
to run, etc.
Objects that conform to the reporter protocol are responsible for
formatting output related to test execution.
Besides providing a way to customize test output, reporters are
essential for another reason: as a way to unit test XCTest itself. Since
XCTest currently prints to stdout, it's difficult to test it without
running it and inspecting its output.
A forthcoming commit will add tests that use a test double as a
reporter, making assertions on what it output by XCTest.
Copy file name to clipboardExpand all lines: XCTest/XCTest.swift
+51-8Lines changed: 51 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -17,6 +17,31 @@ import Glibc
17
17
import Darwin
18
18
#endif
19
19
20
+
/// Not everyone wants to be notified of test results in the same way.
21
+
///
22
+
/// Some people prefer a concise view that fits on a single line, with
23
+
/// dots indicating success and "F" to signify failure: ".....FF..F"
24
+
///
25
+
/// Some prefer a detailed view, containing data on how long each test took
26
+
/// to run, etc.
27
+
///
28
+
/// Objects that conform to the reporter protocol are responsible for
29
+
/// formatting output related to test execution.
30
+
publicprotocolReporter{
31
+
/// Sent when XCTest wishes to log arbitrary information regarding the
32
+
/// a test event.
33
+
///
34
+
/// - Parameter message: The message to log.
35
+
func log(message:String)
36
+
}
37
+
38
+
/// This reporter simply prints each message it is given to stdout.
39
+
privatestructStdOutReporter:Reporter{
40
+
func log(message:String){
41
+
print(message)
42
+
}
43
+
}
44
+
20
45
publicprotocolXCTestCaseProvider{
21
46
// In the Objective-C version of XCTest, it is possible to discover all tests when the test is executed by asking the runtime for all methods and looking for the string "test". In Swift, we ask test providers to tell us the list of tests by implementing this property.
22
47
varallTests:[(String,()->())]{get}
@@ -27,7 +52,6 @@ public protocol XCTestCase : XCTestCaseProvider {
0 commit comments