Skip to content

Instantly share code, notes, and snippets.

@abbeyjackson
Created July 20, 2017 15:21
Show Gist options
  • Save abbeyjackson/d914c8d3805c30e45f86e6390034b7b8 to your computer and use it in GitHub Desktop.
Save abbeyjackson/d914c8d3805c30e45f86e6390034b7b8 to your computer and use it in GitHub Desktop.
Encapsulate common testing code into one function but have the failures/successes show on the line that called the helper function. From Tim Vermeulenon iosdevelopers.io slack
func shared(value: Int, file: StaticString = #file, line: UIInt = #line) {
XCTAssert(value > 10, "value not greater than 10", file: file, line: line)
XCTAssert(value < 20, "value not less than 20", file: file, line: line)
}
func testFoo() {
shared(value: 15) // will pass
}
func testBar() {
shared(value: 25) // will fail
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment