I am new to quick testing, and for now I want to try four tests. I have a segue from ViewController to another (searchForViewController). For this segue, I want to check this 4 things:
- Is there a segue with the id "searchSegue"?
- Is a call to segue called, then I click the "Search by button" button?
- Is the purpose of the Segue SearchedForViewController
- Is Segue replacing the SearchedForVC passed line variable with garten?
My segue in Main.storyboard looks like this:

My code for segue is similar to the following (it works, but for the future I just want to know how to test):
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "searchSegue" {
guard let controller = segue.destination as? SearchedForViewController
else {
return
}
controller.passedString = "garten"
}
}
( ):
class ViewControllerTests: XCTestCase {
var vc: ViewController!
override func setUp() {
super.setUp()
let storyboard = UIStoryboard(name: "Main", bundle: Bundle.main)
vc = storyboard.instantiateViewController(withIdentifier: "test") as! ViewController
let _ = vc.view
}
func testSegueShouldExist() {
let identifiers = getSegues(ofViewController: vc)
XCTAssertEqual(identifiers.count, 1, "Segue count should equal one.")
XCTAssertTrue(identifiers.contains("searchSegue"), "Segue searchSegue should exist.")
}
func testSegueActionsThenPushSearchButton() {
}
func testSegueDirectsToSearchedForViewController() {
}
func testSeguePassedGartenAsValueToSearchedForVC() {
}
}
EDIT , segueShouldExist. . :
func getSegues(ofViewController viewController: UIViewController) -> [String] {
let identifiers = (viewController.value(forKey: "storyboardSegueTemplates") as? [AnyObject])?.flatMap({ $0.value(forKey: "identifier") as? String }) ?? []
return identifiers
}