Xcode tests stuck in testing state

Issue: When I click run unit tests the tests get 'stuck' and in the top bar is says "Testing..." and never completes - I even left it for an hour.

I have created new projects with no code written and the same thing happens.

I have deleted and re-downloaded code as well.

Current Xcode: 14.3

I don't believe it's a project issue since I have tried multiple but rather something with Xcode.

and my CPU % for Xcode shoots to 365+ when this is happening. I have a M1 Max with 64GB.

Any help would be appreciated.

I had the same issue. Don't know if it had any effect, but I moved Xcode from my Downloads folder to Applications, then tried again. It did get stuck, so I started looking at Console to see if there were any clues. While I was doing this the tests eventually started. Took about 5 minutes?

Also had the same issue, what worked is deactivating the "Execute in parallel" in the Tests options (Edit scheme -> Choose Test -> Select Test Plan and go to Options)

28

The same issue

Same here. In addition, when I opened Console, there were a constant stream of Xcode errors similar to this: "found no value for key DVTShowAllSimulatorRunDestinations in CFPrefsSearchListSource<0x600000679780> (Domain: com.apple.dt.Xcode, Container: (null))" Switching off the "Execute in parallel (if possible)" option helped to run tests, but the errors stream in console didn't stop. Xcode Version 15.0 (15A240d).

I have the same problem Xcode 14.3.1, the workaround (disable running tests in parallel) didn't help.

Maybe you use in your XCTestCase

override func setUp(completion: @escaping ((any Error)?) -> Void) { }

    override func tearDown(completion: @escaping ((any Error)?) -> Void) {} 

and never call the completion(), to let it continue

also you can forget to use

expectation.fulfill()

, that in some chain never called, when you use:

let expectation = self.expectation(description: "testCurrentUser")
waitForExpectations(timeout: 5, handler: nil)

Hey, I encountered the same issue with Xcode 15.3 as well. I tried fixing it, but unfortunately, it didn't work for me either.

Here is the sample code:

import XCTest @testable import Dummy

final class CryptoDataAPIResorucesUnitTests: XCTestCase {

func test_CoinAPIResources() {
    let resources = CoinAPIResources(httpUtility: HttpUtility())
    let expectation = self.expectation(description: "CoinAPIResources")
    
    resources.getCoinList { coinData, errorMessage in
        XCTAssertNotNil(coinData)
        XCTAssertNil(errorMessage)
        expectation.fulfill()
    }
    waitForExpectations(timeout: 5)
}

}

Selecting a different Simulator worked for me

I disabled parallelization and it can "work"—I mean, Xcode can launch the test runner app, but one instance will still get stuck and consume up to 70–80 GB of memory.

Finally, I found that when this issue occurs, the Xcode console outputs something like "Interface orientation changed to Portrait" and then gets stuck. So, I tried unchecking all other orientations except Portrait, and it finally worked.

I spent two days on this issue and hope that my findings can help someone who is still struggling with it.

For someone who needs to enable all orientations for their apps, I would suggest checking your code that may be triggered when the device orientation changes. I believe this might be the root cause.

Xcode tests stuck in testing state
 
 
Q