Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save ccabanero/a0fbb675f44a5136d2811d21a77e332a to your computer and use it in GitHub Desktop.

Select an option

Save ccabanero/a0fbb675f44a5136d2811d21a77e332a to your computer and use it in GitHub Desktop.

Revisions

  1. ccabanero renamed this gist May 12, 2016. 1 changed file with 0 additions and 0 deletions.
  2. ccabanero renamed this gist May 12, 2016. 1 changed file with 0 additions and 0 deletions.
  3. ccabanero renamed this gist May 12, 2016. 1 changed file with 0 additions and 0 deletions.
  4. ccabanero revised this gist May 11, 2016. 1 changed file with 33 additions and 1 deletion.
    34 changes: 33 additions & 1 deletion unit test sample - view controller has segue - swift
    Original file line number Diff line number Diff line change
    @@ -47,4 +47,36 @@ class ViewControllerTest: XCTestCase {
    let targetIdentifier = systemUnderTest.segueIdentifierName2
    XCTAssertTrue(hasSegueWithIdentifier(targetIdentifier))
    }
    }
    }

    // Unwind Segue Scenario ... inside ViewControllerTest that has an unwind segue

    ...
    // MARK: - Navigation

    // utility for finding segues
    func hasSegueWithIdentifier(id: String) -> Bool {

    let segues = systemUnderTest.valueForKey("storyboardSegueTemplates") as? [NSObject]
    let filtered = segues?.filter({ $0.valueForKey("identifier") as? String == id })

    return (filtered?.count > 0) ?? false
    }

    func testSUT_HasAnUnwindSegue() {

    let targetIdentifier = systemUnderTest.segueIdentifierUnwindFromPlacesSearchViewController
    XCTAssertTrue(hasSegueWithIdentifier(targetIdentifier))
    }
    ...

    // Unwind Segue Scenario ... inside ViewControllerTest that HANDLES the unwind segue

    ...
    // MARK: - Navigation

    func testSUT_HasUnwindAction_FromPlaceSearchViewController() {

    XCTAssertTrue(systemUnderTest.respondsToSelector(#selector(systemUnderTest.unwindFromPlaceSearchViewController(_:))))
    }
    ...
  5. ccabanero revised this gist May 11, 2016. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions unit test sample - view controller has segue - swift
    Original file line number Diff line number Diff line change
    @@ -38,13 +38,13 @@ class ViewControllerTest: XCTestCase {

    func testSUT_HasSegue_ForTransitioningTo_ViewConrollerOne() {

    let targetIdentifier = systemUnderTest.segueIdentifierToOne
    let targetIdentifier = systemUnderTest.segueIdentifierName1 // segue identifier as a constant property of ViewController
    XCTAssertTrue(hasSegueWithIdentifier(targetIdentifier))
    }

    func testSUT_HasSegue_ForTransitioningTo_ViewConrollerTwo() {

    let targetIdentifier = systemUnderTest.segueIdentifierToTwo
    let targetIdentifier = systemUnderTest.segueIdentifierName2
    XCTAssertTrue(hasSegueWithIdentifier(targetIdentifier))
    }
    }
  6. ccabanero created this gist May 10, 2016.
    50 changes: 50 additions & 0 deletions unit test sample - view controller has segue - swift
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,50 @@
    import XCTest
    @testable import YourProjectModule

    class ViewControllerTest: XCTestCase {

    var systemUnderTest: ViewController!

    override func setUp() {

    super.setUp()

    //get the storyboard the ViewController under test is inside
    let storyboard: UIStoryboard = UIStoryboard(name: "Main_iPhone", bundle: nil)

    //get the ViewController we want to test from the storyboard (note the identifier is the id explicitly set in the identity inspector)
    systemUnderTest = storyboard.instantiateViewControllerWithIdentifier("ViewController") as! ViewController

    //load view hierarchy
    _ = systemUnderTest.view
    }

    override func tearDown() {

    // Put teardown code here. This method is called after the invocation of each test method in the class.
    super.tearDown()
    }

    // MARK: - Storyboard Segues

    // utility for finding segues
    func hasSegueWithIdentifier(id: String) -> Bool {

    let segues = systemUnderTest.valueForKey("storyboardSegueTemplates") as? [NSObject]
    let filtered = segues?.filter({ $0.valueForKey("identifier") as? String == id })

    return (filtered?.count > 0) ?? false
    }

    func testSUT_HasSegue_ForTransitioningTo_ViewConrollerOne() {

    let targetIdentifier = systemUnderTest.segueIdentifierToOne
    XCTAssertTrue(hasSegueWithIdentifier(targetIdentifier))
    }

    func testSUT_HasSegue_ForTransitioningTo_ViewConrollerTwo() {

    let targetIdentifier = systemUnderTest.segueIdentifierToTwo
    XCTAssertTrue(hasSegueWithIdentifier(targetIdentifier))
    }
    }