user2924482
user2924482

Reputation: 9120

XCTest:verify view with tag is presented

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))
}

enter image description here

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

Answers (1)

Herr der Töne
Herr der Töne

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

Related Questions