Test-only Dependencies When Using the Swift Package Manager

1.8k views Asked by At

I've seen mentions of test-only dependencies when using the Swift package manager but haven't been able to get them to work. For example:

https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160104/005409.html https://github.com/apple/swift-package-manager/pull/74 http://blog.krzyzanowskim.com/2016/08/09/package-swift-manual/#testDependencies

What I want is to have the dependency used in my XCtests (e.g., for a specific target), but not applied in the deployed package.

Pointers to working examples would be appreciated.

2

There are 2 answers

2
Vadim Eisenberg On BEST ANSWER

Currently "Test-only dependencies" feature is disabled in the Swift Package Manager. It was implemented initially, but was removed in this commit.

From the commit's description:

Remove testDependencies from PackageDescription This feature was supposed to support dependencies only for the root package but at some point it stopped working however the API still remained open. This patch removes the public API. This is a valid and desired feature which is supposed to come back after it goes through proper review on swift evolution.

0
Lvsti On

@Vadim's answer is correct, there is currently no official API for test dependencies, but there are workarounds. ReactiveSwift for example uses an alternate Package.swift for tests that they overwrite the original one with when executing tests on the CI (see their travis config file). It's not elegant but well, it does the job until SPM brings back this highly needed feature.