Created
November 12, 2017 18:46
-
-
Save ilyapuchka/26431667b986c19b8bf59d83ec80f596 to your computer and use it in GitHub Desktop.
AssertThrow
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
func AssertNoThrow<T>(_ expression: @autoclosure () throws -> T, file: StaticString = #file, line: UInt = #line) rethrows -> T { | |
do { | |
return try expression() | |
} catch { | |
XCTFail("\(error)", file: file, line: line) | |
throw error | |
} | |
} | |
func returnSomethingOrThrow() throws -> Int { ... } | |
class Test: XCTestCase { | |
func testThrowingMethod() throws { | |
let result = try AssertNoThrow(returnSomethingOrThrow()) | |
... | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment