0

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.

user2924482
  • 8,380
  • 23
  • 89
  • 173

1 Answers1

1

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.