Xcode 14.3 freezes doing unit tests some of the time

When I try to run unit tests in Xcode 14.3, it's often freezing up. Needs to be "Force Quit"ed.

This happens most often the first time I try to run a suite through the GUI. Running a single test sometimes freezes, but not always.

I can't pause the test execution, and when I try to exit Xcode it asks if I want to cancel the tests, but then it doesn't cancel them and I need to force quit at that point.

Is there any know issue with 14.3 that would cause this?

Answered by kbrock in 754175022

Our particular issue was related to having a Host Application for testing.

We wanted to run unit tests on a system where, for reasons I won't go into here, we wanted to not run the application itself. We run tests by using the App scheme, which has the test targets listed under the Test option in the scheme editor.

If we set Host Application to none, then Xcode will try to run the unit tests. It will build them, and it will look like it's starting them, but will lock up and require a Force Quit.

  • The unit tests do run fine from the CLI in that case using xcodebuild.
  • If we select the AppUnitTest scheme and run the unit tests then it works, but you can't debug them. Setting breakpoints in the tests doesn't work.

Definitely an Xcode bug--Xcode should never need a Force Quit. If it's a testing scenario it can't handle, it shouldn't run it.

Also, when this is happening there is no high CPU... It looks like basically nothing is happening.

When it locks up trying to quit it's the same thing. No churning CPU, just nothing happening.

Looks like this is connected with having a Swift class that implements a singleton using

@objc class MyClass : NSObject {
    
    static let singleton = MyClass()
    
    @objc class func sharedInstance() -> MyClass {
        return singleton
    }

When I access the class in the test case using:

let myclass = MyClass.sharedInstance()

I get freezes, and when I don't things work fine.

There's no extra initialization being done in the initializer.

Works fine running the unit tests through the CLI, but using the Xcode GUI breaks horribly. No messages about problems, no crashes, but Xcode is dead in the water at that point :-(

Xcode 14.3 RC 2 was freezing yesterday on my 16“ M2 Max MacBook Pro.

I was just changing the iOS Device in Storyboard. Nothing worked anymore, had to hard reboot the MacBook.

Cancel that. Still fails most of the time with the same symptoms & no information from Xcode...

My singleton definition was straight from Apple's docs, but it was definitely the cause of the problem.

I still have no $!!&%^$ idea what was going on, but changing it to

static let singleton : MyClass = { let instance = MyClass() return instance }()

Caused things to start working.

Xcode was ridiculously opaque about what was failing, and why.

I'm having a similar lock-up using Objective-C++ ; I'm not sure the C++ portion is relevant, but I don't think that Swift is required for the problem.

The test I'm seeing hang has been in my codebase since June 2009 with no recent changes. I do link with some Swift code, but it isn't used in these tests.

I have a number of tests that run as part of my build process and I've not had problems before 14.3. However, with this version it's about a 50% chance that one of my test binaries will lock up when run from the GUI.

Running through fastlane or directly through xcode-build.

I do not see these problems on M1 or M2 Macs in our build farm, but I do see it on my x86_64-based MacPro.

I've filed Feedback #FB12154691 on this issue.

Accepted Answer

Our particular issue was related to having a Host Application for testing.

We wanted to run unit tests on a system where, for reasons I won't go into here, we wanted to not run the application itself. We run tests by using the App scheme, which has the test targets listed under the Test option in the scheme editor.

If we set Host Application to none, then Xcode will try to run the unit tests. It will build them, and it will look like it's starting them, but will lock up and require a Force Quit.

  • The unit tests do run fine from the CLI in that case using xcodebuild.
  • If we select the AppUnitTest scheme and run the unit tests then it works, but you can't debug them. Setting breakpoints in the tests doesn't work.

Definitely an Xcode bug--Xcode should never need a Force Quit. If it's a testing scenario it can't handle, it shouldn't run it.

Xcode 14.3 freezes doing unit tests some of the time
 
 
Q