1

I'd like to do some testing on an Alert, UIAlertController. This is what the testing looks like:

class TransactionsListViewControllerTests: XCTestCase {

   private var viewController: MockTransactionsListViewController!

   func testPresentAlertForAccountInCollection() throws {
        let fetchAlertContent = try retrieveAlertContent(mockPath: "alertContent.json", refresh: false)
        if let error = fetchAlertContent.result?.error {
            XCTFail(error.localizedDescription)
            return
        }

        let alertController = UIAlertController(
            title: fetchAlertContent.title,
            message: fetchAlertContent.description, preferredStyle: .alert
        )
        let okButton = UIAlertAction(title: fetchAlertContent.buttonTitle, style: .default)
        alertController.addAction(okButton)
        viewController.present(alertController, animated: false, completion: nil)

        let expectation = XCTestExpectation(description: "show alert")
        DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
            XCTAssertTrue(self.viewController.presentedViewController is UIAlertController)
   expectation.fulfill()
        }
   }
}

What would be the correct way to test that the UIAlertController that is the presented view? The test works fine on my local repository, but when this test is on our work domain (TeamCity), it's facing some issues and referencing another Test in the same module.

The XCTAssertTrue appears to be testing another SnapShot test within the same module and I'm getting issues on GitHub/TeamCity saying that XCTAssertTrue failed with a different test file. I'd like to know how I can improve this testing so that it reference within this file. Hopefully that makes sense, can provide more clarification

rainerwolfram
  • 31
  • 1
  • 3

0 Answers0