Add resources to testTarget with SPM

Hey all,

This is my .testTarget:

  name: "MyProjectTests",
  dependencies: ["MyProject"],
  resources: [.copy("Tests/Resources/crash.json")]

From the project root, crash.json is in ./Tests/Resources/crash.json. I've tried every combination of .copy and .process, just "crash.json", just "Resources", absolute path, relative starting from ., Tests, Resources, but I always get the same error:

warning: 'myproject': Invalid Resource 'Tests/Resources/crash.json': File not found.

Where the path is whatever I write on .copy.

I don't know what else to do. It would seem like the SPM resource feature simply doesn't work. I'm on Xcode 14.2, btw, using // swift-tools-version:5.7.1

All paths in a target declaration are relative to the target root. So the path you're really asking for here from the perspective of the project root is "Tests/MyProjectTests/Tests/Resources/crash.json".

I appreciate your reply. That path doesn't exist, though. The file is in Tests/Resources/crash.json. The swift files are in Tests/MyProjectTests/*.swift, so there's no Tests/MyProjectTests/Tests, either.

I moved the file to Tests/MyProjectTests/Resources/crash.json, and now I get:

warning: 'myproject': Invalid Resource 'Tests/MyProjectTests/Resources/crash.json': File not found.

But now I immediately get:

warning: 'myproject': found 1 file(s) which are unhandled; explicitly declare them as resources or exclude from the target

I think I finally got what you meant. It's working now. I appreciate your help :slight_smile: !