Struggling to add a test target to an existing project in Xcode

Sorry if this question is too vague, however I've tried this multiple times and see the same result. I'm pretty sure I'm doing something wrong, but don't know what.

  1. I have a Multiplatform (iOS and macOS) project that builds, and runs
  2. I add a new target of type Unit Test Bundle
  3. I click the diamond in the margin beside the XCTestCase declaration at the top of the new Test file
  4. The target project builds, then Xcode says 'Testing...' and it stays like this forever.

I've also tried creating a new scheme that targets the target created in the above steps. attempting to run my tests behaves the same. The top status bar will get stuck saying 'Testing...' and never get anywhere.

I'm pretty sure this is something basic. thanks, in advance for any guidance. Mike

What version of Xcode are you running?

Can you run the unit tests if you create a new project and select the Include Tests checkbox?

Does your multi-platform project have one target with multiple destinations or separate targets for iOS and Mac?

If your project has separate targets, which target is your unit test running, the iOS or Mac version?

I was unable to reproduce your issue. I noticed when adding a Unit Test Bundle target to a project with multiple app targets that I had to choose an app target for the unit test bundle. Make sure you have the scheme set to run the app target that matches the target the test bundle is configured to run.

If you recently created your project, you may find it easier to create a new project that includes unit test targets and add whatever code from the first project to the new project.

Hi Szymczyk, thanks for your questions :-)

What version of Xcode are you running?

16.1

Can you run the unit tests if you create a new project and select the Include Tests checkbox?

No. I see the same 'bad' behaviour when I do the following:

  1. Create a new project and choose: Multiproject and Document App (and include Unit and UI test targets)
  2. choose iPhone 16 simulator as the target, Build and Run (app builds and runs fine)
  3. In Xcode, open the Tests file auto created in the Unit tests target
  4. click the diamond to the left of the final class declaration

Build succeeds, but then it spins forever at Testing...

I repeated the above steps, but instead chose App instead of Document App, and I see the same results.

I repeated the above steps again, but chose iOS (instead of Multiplatform) and App. In this case Xcode runs (and passes) the tests. I ran one final test using iOS and Document App. In this case Xcode successfully runs the tests.

I'll look further, but currently it seems like Multiplatform projects in Xcode aren't able to run test targets for me.

thanks again for the questions that helped me move this forward a bit :-)

Mike

Struggling to add a test target to an existing project in Xcode
 
 
Q