Reputation: 9120
I'm adding a view with a tag in viewDidAppear
but I implementing an unit test to verify the view is present in the superview but is returning nil.
Here is my testCase:
func testVerifiedViewWithTagIsLoadIt() {
let sut = ViewController()
_ = sut.view
let view = sut.view.viewWithTag(10)
XCTAssertNotNil(view)
XCTAssertNotNil(sut.view.viewWithTag(10))
}
My question is how can I verify the view with tag is load it from XCTest?
I'll really appreciate your help.
Upvotes: 0
Views: 235
Reputation: 178
The problem is viewDidAppear
won't get called on sut
in your test. Asking for the ViewControllers view
will only trigger viewDidLoad
. So you probably want to add the tagged View in viewDidLoad
!
If you do that your test will pass.
Upvotes: 1