[swift-users] How to include swift test resource files?

Daniel Dunbar daniel_dunbar at apple.com
Thu Nov 10 11:44:53 CST 2016

We do not yet have any kind of story for resources.

If you just need data during tests, what you can do is just rely on the tests being run in an environment which has access to the source, so you can use Swift's `#file` to derive the location of your test artifacts from the current source file path.

This is kind of a hack, but it works. Example:

 - Daniel

> On Nov 10, 2016, at 9:29 AM, Edward Connell <ewconnell at gmail.com> wrote:
> Swift test builds and runs the package Tests. My tests require data files such as images to run. 
> With an Xcode project we can Copy Bundle Resources in the Build Phases to include the necessary files.
> How do we do this with swift test, or swift build?
> I thought about a hack to manually copy the resource files, but since "swift test" builds and runs the tests as a single action there doesn't seem to be an opportunity.
> How do we include package resources during build and test?
> Thanks, Ed

More information about the swift-users mailing list