Created
August 22, 2016 09:53
-
-
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)
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 | |
@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