[swift-corelibs-dev] testing guidance
jp at jpsim.com
Mon Feb 8 18:48:24 CST 2016
I think this question is better suited for the swift-users mailing list,
but I'll answer here since that's where you posted this.
The solution I've found is full of caveats, but it does run tests with
swift-corelibs-xctest on Darwin.
The trick is to build your unit tests as an executable target with your
main module as a dependency, and to add swift-corelibs-xctest as a
let package = Package(
dependencies: [.Target(name: "MyPackage")]),
Note that the XCTest git URL used here isn't the official one, since it
doesn't yet have an SPM-compatible version tag. So you can fork it and add
a tag like Norio did (0.1.0-test). Then you can run your tests by running swift
build followed by .build/Debug/MyPackageTests.
However, please note that by doing this, you're introducing a target with a
local dependency, which means that others won't be able to use your package
as a dependency due to SR-688 <https://bugs.swift.org/browse/SR-688>.
I'm testing my projects on Darwin in both Xcode and SPM, using Darwin
XCTest in Xcode, and swift-corelibs-xctest in SPM.
You can see the approach we take (including testing on Travis) in
SourceKitten <https://github.com/jpsim/SourceKitten> and SwiftLint
<https://github.com/realm/SwiftLint>. The relevant files are Package.swift,
Makefile and .travis.yml.
I'm hoping that others can share nicer solutions to this as well, but in
the meantime, hopefully this gets you unstuck.
On Mon, Feb 8, 2016 at 11:12 AM, Scott Guyer via swift-corelibs-dev <
swift-corelibs-dev at swift.org> wrote:
> Hi folks,
> I've tried to determine the current best practice for managing projects
> with tests. I figure I would just ask ...
> Scenario: I have a project with a code module and a test module. I need it
> to run on both macosx (darwin) as well as Linux.
> Using swiftpm on Linux works fine. It fails on macosx (the error is that
> an underlying dependency for XCTest cannot be loaded). What I read is that
> corelibs-xctest was not meant to be run on Darwin. I'm coming to the
> conclusion that I should have a .xcodeproj with a framework target and test
> target for Darwin testing. Leaving the swiftpm approach for Linux only.
> Does that sound about right?
> swift-corelibs-dev mailing list
> swift-corelibs-dev at swift.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-corelibs-dev