Running SPM Tests inside project


I'm trying to run unit tests from a package inside of the project that uses it as a dependency. Is this possible?

An example of this would be making a new package, making a new app, and downloading the package as a dependency.

example package file

// swift-tools-version: 5.7
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
    name: "MyLibrary",
    products: [
            name: "MyLibrary",
            targets: ["MyLibrary"]),
    dependencies: [],
    targets: [
            name: "MyLibrary",
            dependencies: []),
            name: "MyLibraryTests",
            dependencies: ["MyLibrary"]),

I'm not sure if this is the problem, but when I click Edit Scheme of the imported package, it says the tests are missing.

Do you have any tests inside the test target? What happens if you just type swift test on the command line to run them outside of Xcode?

Hey Tim,

Running swift test on the project does nothing.
Running swift test on the package runs the tests.

I should probably also mention that the packages I'm using are all my own for modulation. And the real issue I'm trying to accomplish here is having the tests in the package run daily as a part of my Xcode Cloud workflow for the app that uses them.

Obviously I could duplicate the tests from the packages into the project itself, but I figured there must be an easier, less redundant way?

Running tests of remote dependencies is not directly possible. Is creating a separate XcodeCloud workflow for the package an option?

Hey Boris,

Thank you for that answer. - I don't have a problem with running the tests in the packages separate from the app. That also makes sense. The issue I ran into with trying to do that is that the package is not an App or Framework, so there's no option to create an Xcode Cloud Workflow.