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/dd35e7bee8205ad225f3de1391027aa5 to your computer and use it in GitHub Desktop.
Save ccabanero/dd35e7bee8205ad225f3de1391027aa5 to your computer and use it in GitHub Desktop.
Sample iOS Unit Tests: Working with a ViewConroller that uses CoreLocation
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