Skip to content

Instantly share code, notes, and snippets.

@darthpelo
Created August 22, 2016 09:53
Show Gist options
  • Save darthpelo/e2874c5bfa592f8f9c3bac76f60cdff0 to your computer and use it in GitHub Desktop.
Save darthpelo/e2874c5bfa592f8f9c3bac76f60cdff0 to your computer and use it in GitHub Desktop.
How to setup a UIViewController and test it with Unit Test (Swift 3)
import XCTest
@testable import MyProject
class MyProjectTests: XCTestCase {
var mainvc: MyProject.ViewController!
private func setUpViewControllers() {
let storyboard = UIStoryboard(name: "Main", bundle: Bundle.main)
self.mainvc = storyboard.instantiateViewControllerWithIdentifier("MainVC") as! MyProject.ViewController //
self.mainvc.loadView()
self.mainvc.viewDidLoad()
}
override func setUp() {
super.setUp()
self.setUpViewControllers()
}
override func tearDown() {
mainvc = nil
super.tearDown()
}
func testMainVC() {
XCTAssertNotNil(self.mainvc, "Main VC is nil")
XCTAssertNotNil(self.mainvc.button, "Button is nil")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment