XCTestCase subclass implementation is below:
import XCTest
@testable import AppName
class SomeTestClass: XCTestCase {
var viewController: AppName.ViewControllerName?
override func setUp() {
super.setUp()
viewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("someIdentifier") as? AppName.ViewControllerName // Line 7
_ = viewController?.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 testIfCaseInteractionLabelIsNotNil() {
XCTAssertNotNil(viewController?.someLabel)
}
}
In the code above the type of view controller object is "AppName.ViewControllerName" if I specify it as just ViewControllerName like below, the test fails because of casting in line 7
var viewController: ViewControllerName?
override func setUp() {
super.setUp()
viewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("someIdentifier") as? ViewControllerName // Line 7
_ = viewController?.view
}
I tried making the view controller class public and using @testable annotation in swift2. It doesn't work.
I made "Enable Testability" build setting to YES.
The code works even if I don't use @testable import but in lot of blogs and tutorials, this results in error.
Any help would be appreciated! Thanks in advance