SwiftPM and Library Unit Testing

One issue with the committed generated schemes for the unit tests is that they propagate as clutter to library clients. See Firebase Flooding Project with Build Schemes · Issue #8167 · firebase/firebase-ios-sdk · GitHub.

Is there anyway to keep package schemes from showing up in client apps? Or any progress on the original issue of automated scheme generation support for library products?

2 Likes

Like we have swift build --target TargetName, do we have command to test specific target like swift test --target TargetName?

Yes we do:

swift test --filter TargetName

Run swift test --help for more information.

I am updating an internal SwiftPM package we've had for a few years. The package in the past was testable on macOS and the iOS simulator.

I am now adding an executable product and executableTarget that is macOS only. Is there a way to mark those product/target to only build on macOS?

More Details With Code Really the problem is that adding an `executableTarget` with `resources` leads to Xcode attempting to run `codesign`. Which then fails the build.
...
CodeSign /Users/lovelettr/Desktop/example-2/derivedData/Build/Products/Debug-iphonesimulator/example-1_example-2.bundle (in target 'example-1_example-2' from project 'example-1')
    cd /Users/lovelettr/Desktop/example-2

    Signing Identity:     "-"

    /usr/bin/codesign --force --sign - --timestamp\=none --generate-entitlement-der /Users/lovelettr/Desktop/example-2/derivedData/Build/Products/Debug-iphonesimulator/example-1_example-2.bundle
/Users/lovelettr/Desktop/example-2/derivedData/Build/Products/Debug-iphonesimulator/example-1_example-2.bundle: bundle format unrecognized, invalid, or unsuitable
Command CodeSign failed with a nonzero exit code

If you want to replicate the error locally go to: RLovelett/swiftpm-and-library-unit-testing: This is an example SwiftPM Package used to illustrate an error discussed on the Swift Forums (github.com) and run build.sh.

Resurrecting an old thread, but for some reason I can't get it to work here:

I'm calling xcodebuild -scheme Swift-Automotive-Package test -sdk iphoneos -destination "platform=iOS,name=M15", but it errors out with

xcodebuild: error: Failed to build workspace Swift-Automotive with scheme Swift-Automotive-Package.: Cannot test target “Swift-Automotive-Tests” on “M15”: Tool-hosted testing is unavailable on device destinations. Select a host application for the test target, or use a simulator destination instead.

On-device testing requires a host app, so it isn't available to standalone packages.

You can either run the tests via a simulator destination or you will have to create an Xcode project with a host app and then you should be able to run them specifying an override for TEST_HOST via xcodebuild, but I am not super familiar with that flow, so there might be more steps involved.

1 Like