Skip to content

Instantly share code, notes, and snippets.

@scotteg
Created December 25, 2014 16:22
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 scotteg/12322fbb8c00a55656da to your computer and use it in GitHub Desktop.
Save scotteg/12322fbb8c00a55656da to your computer and use it in GitHub Desktop.
How to use XCTest in Swift with an optional
func testCopyingLists() {
if let listCopy = list.copy() as? List {
XCTAssertEqual(list, listCopy, "listCopy should be equal to list")
} else {
XCTFail("listCopy should not be nil")
}
}
@almassapargali
Copy link

@scotteg looks legit, though this would fail not only when list.copy() returns nil, but also when it returns instance of other classes.

@almassapargali
Copy link

Don't know even, I think it depends on context and personal tastes. For example, I have a tests which tests JSON values and if it has value then tests it's type.

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