Last active
October 1, 2018 15:52
-
-
Save ccabanero/dd35e7bee8205ad225f3de1391027aa5 to your computer and use it in GitHub Desktop.
Sample iOS Unit Tests: Working with a ViewConroller that uses CoreLocation
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
import XCTest | |
import CoreLocation | |
@testable import MyProject | |
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() | |
} | |
func testSUT_CanBeInstantiated() { | |
XCTAssertNotNil(systemUnderTest) | |
} | |
// MARK: - core location | |
func testSUT_ConformsToCLLocationManagerProtocol() { | |
XCTAssert(systemUnderTest.conformsToProtocol(CLLocationManagerDelegate)) | |
XCTAssertTrue(systemUnderTest.respondsToSelector(#selector(systemUnderTest.locationManager(_:didUpdateLocations:)))) | |
XCTAssertTrue(systemUnderTest.respondsToSelector(#selector(systemUnderTest.locationManager(_:didFailWithError:)))) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment