_XCTFailInCurrentTest should only be called while a test is running - ios

I am now doing for UITesting with Xcode and I got this error.
* Assertion failure in void _XCTFailInCurrentTest(NSString *,
...)(),
/Library/Caches/com.apple.xbs/Sources/XCTest_Sim/XCTest-10112/XCTestFramework/Classes/XCTestCase.m:63
2016-05-13 22:31:54.961 XCTRunner[15428:168507] * Terminating app
due to uncaught exception 'NSInternalInconsistencyException', reason:
'_XCTFailInCurrentTest should only be called while a test is running.
Failure description: Failed to receive completion for
I have seen other similar post here.
Cannot run Xcode (7.3) UI tests in Jenkins
I am using Jenkins but for now, I am directly running from Xcode and I can't even run from Xcode. How shall I do?

Background
I faced this issue in Xcode 7.3 (7D175) and iOS Simulator 9.3.
The symptoms were as follows
the Test Runner launches normally and exits.
Following this, the app under test never launches.
(if the app under test was not installed, Xcode will also never install the app prior to starting the test).
(a side symptom is that recording also does not work for me - I took inspiration from this SO post.)
After 30 seconds the test times out with:
XCTRunner[36260:489138] Continuing to run tests in the background with task ID 1
2016-05-18 16:17:25.720 XCTRunner[36260:489138] *** Assertion failure in void _XCTFailInCurrentTest(NSString *, ...)(), /Library/Caches/com.apple.xbs/Sources/XCTest_Sim/XCTest-10112/XCTestFramework/Classes/XCTestCase.m:63
2016-05-18 16:17:25.723 XCTRunner[36260:489138] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '_XCTFailInCurrentTest should only be called while a test is running.
Failure description: Failed to receive completion for <XCDeviceEvent:0x7fddc241f970 page 12 usage 64 duration 0.01s within 30.0s'
The fix that worked for me was:
reset the simulator.
check whether the deployment target is set to iOS 9.x in the build settings for the UI Test Target. (in my case it was set to iOS 8)
after changing the target, clean and rebuild.
After following these steps, Xcode was able to install the app prior to the test, recording worked, and the error went away.

By some reason simulator got corrupted. In my case it was not possible to launch any test once get at the same point. In my case what it worked was reset simulator (Menu Simulator|Reset Contents and Settings...) or switch to any other simulator.

We tried the tips from the other responses, which did not work for us.
A complete reinstall of Xcode 7.3 fixed our issue.
remove Xcode
restart
reinstall Xcode
success

Related

How to debug "Error acquiring assertion" with CloudKit database subscription for mac-catalyst app?

I have a working native iPhone/iPad app that I’m now trying to also do as a Mac Catalyst app. Everything seems to working, except when I enter something on the iOS version, it "breaks" the macOS version – I’m using CloudKit and CloudKit subscriptions to listen to changes in database.
I get this into the log 3 times:
2020-04-25 09:58:35.612887+0300 MyApp[2871:206093] [assertion] Error acquiring assertion: <NSError: 0x600000d4cb40; domain: RBSAssertionErrorDomain; code: 2; reason: "Specified target process does not exist">
2020-04-25 09:58:35.613919+0300 MyApp[2871:206093] [assertion] Error acquiring assertion: <NSError: 0x600000d4d290; domain: RBSAssertionErrorDomain; code: 2; reason: "Specified target process does not exist">
2020-04-25 09:58:35.615102+0300 MyApp[2871:206093] [assertion] Error acquiring assertion: <NSError: 0x600000d4de00; domain: RBSAssertionErrorDomain; code: 2; reason: "Specified target process does not exist">
The behaviour is really strange. The macOS version doesn’t actually crash, but the main window disappears and I have to rebuild it in XCode the run it again. I’ve tried adding breakpoints etc to the notifications flow, but there’s nothing that catches so I’m really stumped. None of the usual application methods are called when the notification is received. The same problem appears in debug mode, both with simulator and device, and also in production.
Really hoping to get some pointers, where/how to debug this kind of a problem. I’ve checked the system logs and cannot find anything there either.
Just ran into this myself, and eventually figured it out: you probably have more than one instance of the app (with that bundle ID) on your machine, and the push notification service is trying to spin up the wrong binary to deliver the notifications.
Since Catalyst apps get nuked if they try to open multiple instances, this background launch kills the app you're running in the debugger.
In my case, I had the App Store version of the app installed in /Applications (before I started adding CloudKit), and my current dev binary in my Xcode build root.
Hope that helps!

Unit test error in Xcode 9 and Simulator iOS 11

I get the following error in Xcode 9 and Simulators with iOS 11. It's very weird as all the test cases are running fine in Xcode 9 with simulator iOS 9. It seems to be some kind of issue with Xcode 9 and Simulator iOS 11.
Assertion failure in void _XCTestMain(XCTestConfiguration *)(),
/Library/Caches/com.apple.xbs/Sources/XCTest_Sim/XCTest-13201/Sources/XCTestFramework/Harness/XCTestMain.m:62
2017-11-06 16:26:51.080851-0600 xctest
[17644:81518] Terminating app due to uncaught exception
'NSInternalInconsistencyException', reason: 'No test bundle found at
file:///Users/xxxx/Code/iOS-SDK/ContentSDK/build/Debug/ContentSDKTests.xctest/
For me the problem was in the lowercase letter in 'build' directory name. I used parameter '-derivedDataPath build' for xcodebuild. Try to compare the real build directory name on the filesystem with the name in the error message.
It's a wired issue. I have created a simulator from Xcode -> window-< Devices & simulators and the unit test started working fine.

UI Tests no longer working on Xcode 7.3

I have a set of XCUITests that run with our iOS app. They used to run fine on Xcode 7.2.1, but upgrading to 7.3 causes tests to fail in the "Set Up -> Wait for app to idle" phase with the following error:
UI Testing Failure - Failed to perform AX action for monitoring the animations of <XCUIApplicationProcess: 0x7f82450288c0 [appName here] (25670)>, error: Error -25204 performing AXAction 2043
This failure is seen on every single UI test, both on bots and when running locally.
Has anyone else seen this or have any workarounds?
In case anyone still has this issue - for me it was activating the Optimizely framework that caused this error. Disabling the framework when running XCUITest solved it for me.
Note to self: Don't have code that crashes your app on purpose while tests are trying to run. D:
Basically there was a call to terminate the app within the launch phase of the app for a certain scheme (in our case, the TEST scheme). Be thorough in checking what the app is doing when it launches for testing, because there might be errant behavior.

Simple XCTest for UITest is failing all the time?

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:
Now test is successful! Anyone can explain the reason?
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.
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.

iOS app crashing immediately

My iOS app is crashing immediately without any debug info. I have a break point all objective-c exceptions.
Crashing on this line
return UIApplicationMain(argc, argv, nil, NSStringFromClass([STAppDelegate class]));
App was running fine for the past month and nothing was changed.
I cleaned are re-ran.
What is weird is it is crashing every other time I run so run once its good stop it and run again crashed .... repeat rinse same result... every other time.
I am getting closer after installing 4.6.2. Now it crashes everytime and I get this error."erminating app due to uncaught exception 'NSInvalidUnarchiveOperationException', reason: 'Could not instantiate class named UIStoryboardUnwindSegueTemplate'"
This is an altogether different story, it looks like a problem similar to use autolayout on iOS version lower than 6.x...
You cannot use storyboard with iOS 5.x as deployment target.
Getting back to your original problem, Xcode 4.6.2 app crashes on every second run, it gets solved either updating to the latest XCode 4.6.3 or using GDB instead of LLDB. I suggest, however, to update to the latest version and hence use LLDB - by the way, it looks like the next XCode 5 will support exclusively LLDB.

Resources