Last active
April 15, 2020 10:39
-
-
Save ccabanero/308db4882b7ca4967ebb5d17530177f3 to your computer and use it in GitHub Desktop.
Sample iOS Unit Tests: Testing Segue passes data to Target ViewController
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This doesn't work bc your callingViewController has no member placeDetailsViewControllerSegue.
Where did you pull that method/property from??