-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38 from bow-swift/nef_testing
`nef` boilerplate for testing
- Loading branch information
Showing
4 changed files
with
103 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import Foundation | ||
import XCTest | ||
|
||
public extension Nef { | ||
|
||
static func run<T: XCTestCase>(testCase class: T.Type) { | ||
startTestObserver() | ||
T.defaultTestSuite.run() | ||
} | ||
|
||
static private func startTestObserver() { | ||
_ = testObserverInstalled | ||
} | ||
|
||
static private var testObserverInstalled = { () -> NefTestFailObserver in | ||
let testObserver = NefTestFailObserver() | ||
XCTestObservationCenter.shared.addTestObserver(testObserver) | ||
return testObserver | ||
}() | ||
} | ||
|
||
// MARK: enrich the output for XCTest | ||
fileprivate class NefTestFailObserver: NSObject, XCTestObservation { | ||
|
||
private var numberOfFailedTests = 0 | ||
|
||
func testSuiteWillStart(_ testSuite: XCTestSuite) { | ||
numberOfFailedTests = 0 | ||
} | ||
|
||
func testSuiteDidFinish(_ testSuite: XCTestSuite) { | ||
if numberOfFailedTests > 0 { | ||
print("💢 Test Suite '\(testSuite.name)' finished with \(numberOfFailedTests) failed \(numberOfFailedTests > 1 ? "tests" : "test").") | ||
} else { | ||
print("🔅 Test Suite '\(testSuite.name)' finished successfully.") | ||
} | ||
} | ||
|
||
func testCase(_ testCase: XCTestCase, | ||
didFailWithDescription description: String, | ||
inFile filePath: String?, | ||
atLine lineNumber: Int) { | ||
|
||
numberOfFailedTests += 1 | ||
print("❗️Test Fail '\(testCase.name)':\(UInt(lineNumber)): \(description.description)") | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
template/ios/PROJECT.playground/playground.xcworkspace/contents.xcworkspacedata
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import Foundation | ||
import XCTest | ||
|
||
public enum Nef {} | ||
|
||
public extension Nef { | ||
|
||
static func run<T: XCTestCase>(testCase class: T.Type) { | ||
startTestObserver() | ||
T.defaultTestSuite.run() | ||
} | ||
|
||
static private func startTestObserver() { | ||
_ = testObserverInstalled | ||
} | ||
|
||
static private var testObserverInstalled = { () -> NefTestFailObserver in | ||
let testObserver = NefTestFailObserver() | ||
XCTestObservationCenter.shared.addTestObserver(testObserver) | ||
return testObserver | ||
}() | ||
} | ||
|
||
// MARK: enrich the output for XCTest | ||
fileprivate class NefTestFailObserver: NSObject, XCTestObservation { | ||
|
||
private var numberOfFailedTests = 0 | ||
|
||
func testSuiteWillStart(_ testSuite: XCTestSuite) { | ||
numberOfFailedTests = 0 | ||
} | ||
|
||
func testSuiteDidFinish(_ testSuite: XCTestSuite) { | ||
if numberOfFailedTests > 0 { | ||
print("💢 Test Suite '\(testSuite.name)' finished with \(numberOfFailedTests) failed \(numberOfFailedTests > 1 ? "tests" : "test").") | ||
} else { | ||
print("🔅 Test Suite '\(testSuite.name)' finished successfully.") | ||
} | ||
} | ||
|
||
func testCase(_ testCase: XCTestCase, | ||
didFailWithDescription description: String, | ||
inFile filePath: String?, | ||
atLine lineNumber: Int) { | ||
|
||
numberOfFailedTests += 1 | ||
print("❗️Test Fail '\(testCase.name)':\(UInt(lineNumber)): \(description.description)") | ||
} | ||
} |