Open premedios opened 7 years ago
You can do it something like below
class MyViewControllerTests: XCTestCase { // MARK: - Subject under test
var sut: MyViewController!
var window: UIWindow!
// MARK: - Test lifecycle
override func setUp() {
super.setUp()
window = UIWindow()
setupMyViewController()
}
override func tearDown() {
window = nil
super.tearDown()
}
// MARK: - Test setup
func setupMyViewController() {
sut = MyViewController.instance()
loadView()
addViewToWindow()
}
func loadView() {
let _ = sut.view
}
func addViewToWindow() {
window.addSubview(sut.view)
RunLoop.current.run(until: Date() as Date)
}
// MARK: - Test doubles
// MARK: - Tests
...
}
If my UI was being created by code, how would I go about testing the output in the view controller?