jeudi 28 avril 2016

XCode 7.3 SDK iOS 9.3, XCTest UI unit tests failing

I have been using XCTest UI unit tests in my app, it worked great with XCode 7.2. with base SDK iOS 9.2, but as soon as I tried to run them with XCode 7.3, with bas SDK iOS 9.3, all of them are failing.

After looking at the issue, it seems that after the app launches, it tries to tap on the buttons a little too fast, note that at this point I can assert for the existance of the button with a simple NSPredicate, and it does in fact exist, the engine finds it, but when it tries the tap, despite not failing in the logs, the method for the IBAction does NOT get called. I created a brand new project to test this issue, first I simply created a single view application, no navigation controller involved, with a single UIButton, and hooked up the IBAction to the view controller, then simply added this UI unit test:

    func testExample()
{
    XCUIApplication().buttons["Button"].tap()
}

And set a breakpoint in the IBAction method on my view controller, it got called. Then I decided to make my view controller with the button the root view controller of a UINavigationController, ran the same test, and now the tap does not work!. If I add a simple delay such as:

    func testExample()
{
    sleep(1)
    XCUIApplication().buttons["Button"].tap()
}

Then the button tap happens, and the executions stops on the IBAction breakpoint, If I run this code without the sleep in XCode 7.2. it also gets called. There seems to be a definite problem with XCode 7.3 or rather iOS Base SDK 9.3, with XCTest UI testing, I know i can simply add sleep at setUp for all test cases, and they work, however this is a big hack, surprisingly I could not find any topics online with this issue, anyone else experiencing the same and has a good work around for it?

Aucun commentaire:

Enregistrer un commentaire