Skip to content

Instantly share code, notes, and snippets.

@loganblevins
Created October 16, 2024 17:14
Show Gist options
  • Save loganblevins/1e3bafc3d5804b6b4292113943b605ec to your computer and use it in GitHub Desktop.
Save loganblevins/1e3bafc3d5804b6b4292113943b605ec to your computer and use it in GitHub Desktop.
XCTestCase+teardown
extension XCTestCase {
func trackForMemoryLeaks(_ instance: AnyObject, file: StaticString = #filePath, line: UInt = #line) {
addTeardownBlock { [weak instance] in
XCTAssertNil(instance, "Instance should have been deallocated. Potential memory leak.", file: file, line: line)
}
}
}
@loganblevins
Copy link
Author

loganblevins commented Oct 16, 2024

private func getSUT(file: StaticString = #filePath, line: UInt = #line) -> Something {
    let sut = Something()
    trackForMemoryLeaks(instance: sut, file: file, line: line)
    return sut
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment