Xcode Cloud: How to trigger testing for packages?

Hello!

I have a Swift package (SPM) with a number of tests associated with it. These all work well locally, and I have created a GitHub repository for the package that can be used by any app.

I would like to set it up where my package's tests are triggered automatically whenever I push a change to a branch in the repository.

Unfortunately, per the documentation, Xcode Cloud is currently unable to build and test standalone Swift packages. I hope that this will be rectified some point soon as automated testing for them seems like it'd be a pretty common and understandable use case.

My question: Is there a way to set an Xcode Cloud workflow up wherein a package's tests are triggered?

Xcode Cloud clearly does support Swift packages that are used when building full apps, and there is plenty of documentation to that end. But it's not clear how to trigger those package's tests even through the use of a "dummy" app without moving a bunch of tests to the app itself.

Is this possible?

I'd really not like to duplicate all my tests in a dummy app if at all possible.

Thanks!

Replies

I use a workaround:

  1. Create a new Xcode project, in the same git repo as your-swift-package, without adding any source code files.

  2. Add your-swift-package as a local package to your Xcode project (File-> Add Packages)

  3. Add your-swift-package as a dependency to the Xcode project's target (In the Xcode project select the target and add framework as usual)

  4. Add the test target of your-swift-package to the test scheme of the project (Open the scheme editor in the Xcode project, in test-phase, info tab, add the test target of your-swift-package to the enabled tests using the '+' button

  5. Configure the Xcode project to build in Xcode Cloud

I hope that Apple will soon support building stand alone swift packages, so we do not need this additional workaround.

I just stumbled into this forum post from Mastodon, but I can at least share how I've set this up for one of my projects, Fedigardens.

Fedigardens has a workspace that I use which contains the main iOS app project and all of its internal Swift packages like networking libraries and feature modules. I have a test plan file that contains the tests that I want to execute, which is tied to the main app's scheme. When I set up the testing workflow, I made sure to select the test plan I created with all the unit tests. Suffice to say, this approach seems to work well for my use cases.

So, a step-by-step process:

  1. Create an Xcode workspace and iOS app project.
  2. Add the Swift packages and iOS app to that workspace.
  3. Create a test plan file (.xctestplan) by going to File > New > File... and select 'Test Plan'.
  4. In that test plan, add the Swift package tests (and any other tests) you'd like to execute.
  5. In the test section of the iOS app's scheme, add the existing test plan you created.
  6. Create an Xcode Cloud workflow as usual, targeting the test plan when adding the test action.