How to include swift test resource files?


(Edward Connell) #1

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


(Daniel Dunbar) #2

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:
  https://github.com/apple/swift-package-manager/blob/master/Sources/TestSupport/misc.swift#L38

- Daniel

···

On Nov 10, 2016, at 9:29 AM, Edward Connell <ewconnell@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