Reputation: 320
Let me explain a bit of the context. Our project has 1 framework target and 1 test app target that consumes the framework. All logic and code goes to the framework and the test app only imports the framework. No logic is included in the test app.
Now these are my 2 problems:
1. Xcode can't find the class (SearchVC) I declared within the framework target from my XCTest class. I get "Use of unresolved identifier" when I try to create an instance from the class. However, I have no problems when making instances from other classes in the framework target. In fact, I create a property (of type SearchVC) into another class (DashboardVC) and I can access and initialize it correctly, which takes me to the next problem.
2. Xcode can't find the internal property (of type SearchVC) I created (in DashboardVC) from the XCTest class. I'm able to find any other internal properties except this new one.
Things to consider:
These are simplified snippets of the classes.
class DashboardVC : UIViewController, UITableViewDelegate, UITableViewDataSource {
... many other properties ...
var searchVC: SearchVC!
override func viewDidLoad() {
super.viewDidLoad()
searchVC = SearchVC()
}
}
Now the second class
class SearchVC: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
Then I have been trying to write the following test member of the Test target.
import XCTest
@testable import Invest
class SearchVC: XCTestCase {
... setup and tearDown methods not included for clarity ...
func testSearchVC_isAddedToDashboard() {
let dashboard = DashboardVC()
_ = dashboard.view
XCTAssertNotNil(dashboard.searchVC.view, "View should not be nil")
}
}
Any ideas why this might be happening or how to work around it?
Thank you
Upvotes: 1
Views: 1477
Reputation: 320
I was finally able to make it work. It turned out to be a glitch from Xcode. For unexplainable reasons, I was able to pull from the latest version of our code and even though I was getting errors, I was able to solve those by taking out every non-test class from the Test Target (the way it should be) and only keep the relevant classes. I was able to access my property and keep the correct separation between Targets.
Has anybody experienced the same glitches?
Upvotes: 1