Simple XCTest for UITest is failing all the time?
Asked Answered
F

2

6

I start a new project from File -> New -> project

I add a button to ViewController.

I open UITest folder which created by xcode by default. Run the test code.

It fails:

2016-03-16 12:57:09.191 XCTRunner[3511:150419] Continuing to run tests in the background with task ID 1
    t =    10.18s         Assertion Failure: UI Testing Failure - Failed to background test runner.
/Users/Bernard/Desktop/ExampleTestApplication/ExampleTestApplicationUITests/test2.m:27: error: -[test2 testExample] : UI Testing Failure - Failed to background test runner.
2016-03-16 12:57:12.789 XCTRunner[3511:150419] *** Terminating app due to uncaught exception '_XCTestCaseInterruptionException', reason: 'Interrupting test'

Now I add a break point as follow:

enter image description here

Now test is successful! Anyone can explain the reason?

Flocculant answered 16/3, 2016 at 2:3 Comment(6)
i have faced the same issue (kind of) some time back.I noticed that this crash might be related to the app launching handling. Apple seems to have set a timeout for the testing instance and if the instance didn't get response from your app before the timeout, the instance will be terminated and the app crashes at the [app launch]; position.Langobard
@Langobard Am I able to change this timeout time and my app has only one view!!!Flocculant
AFAIK we dont have access to change the time out.Langobard
@Langobard How did you fix this problem then?Flocculant
i am not sure this is what exact issue you have. But it got fixed when i tested the same code in OS X server, weird but now working fineLangobard
as for me a workaround is to build the app before first running test.Girlfriend
C
1

I was also facing same issues and none of the available solutions worked for me. Issue was not letting app to attach to the simulator itself. I checked the log and saw that i did a mistake in code while locating the element. for Predicate instead of BEGINSWITH i wrote STARTSWITH and this was stopping the app to get attached. So check your logs in the test report to get the issue.

Chev answered 7/7, 2017 at 19:23 Comment(0)
M
0

I was getting this error happening when the iOS simulator was already launched (which may not necessarily mean you can see it in the OS X dock). You can check the state of the various simulators using the simctl command.

I.e.

xcrun simctl list devices

Then, ensure that any devices listed as "Booted" are shutdown:

xcrun simctl shutdown <device-udid-here>

Then, try running your UI tests again.

Misbelief answered 23/5, 2016 at 21:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.