Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ccabanero/308db4882b7ca4967ebb5d17530177f3 to your computer and use it in GitHub Desktop.
Save ccabanero/308db4882b7ca4967ebb5d17530177f3 to your computer and use it in GitHub Desktop.
Sample iOS Unit Tests: Testing Segue passes data to Target ViewController
func testSUT_PassesDataToTargetViewController() {
// declare the storyboard, source view controller, and target view controller
let storyboard: UIStoryboard = UIStoryboard(name: "Main_iPhone", bundle: nil)
let callingViewController = storyboard.instantiateViewControllerWithIdentifier("PlaceListViewController") as! PlaceListViewController
let targetViewController = storyboard.instantiateViewControllerWithIdentifier("PlaceDetailsViewController") as! PlaceDetailsViewController
// fetch the segue from story board
let targetSegue: UIStoryboardSegue = UIStoryboardSegue(identifier: callingViewController.placeDetailsViewControllerSegue, source: callingViewController, destination: targetViewController)
// simulate when user taps a cell - we get the associated model object and send its id (of type Int) as the sender parameter of prepareForSegue()
let tappedModelId = 16202
callingViewController.prepareForSegue(targetSegue, sender: tappedModelId)
// confirm that prepareForSegue() properly sets the 'placeId' property of the destination view controller
XCTAssertEqual(tappedModelId, targetViewController.placeId)
}
@johnpitts
Copy link

This doesn't work bc your callingViewController has no member placeDetailsViewControllerSegue.
Where did you pull that method/property from??

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