Skip to content

Instantly share code, notes, and snippets.

@ilyapuchka
Created November 12, 2017 18:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ilyapuchka/26431667b986c19b8bf59d83ec80f596 to your computer and use it in GitHub Desktop.
Save ilyapuchka/26431667b986c19b8bf59d83ec80f596 to your computer and use it in GitHub Desktop.
AssertThrow
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