I\'m running swift test from the command line to run the test cases. This is the test case:
import XCTest
@testable import vnk_swift
class KeyM
This seems to be caused my having a main.swift in your module directory. This results in an executable being build, instead of a library against which your test cases can be linked.
I resolved this issue by splitting my code into two modules. A library for which I have test cases and the application that only contains main.swift:
Package.swift
Sources\FooBarLib\
Sources\FooBarLib\Something.swift
Sources\FooBarLib\MoreStuff.swift
Sources\FooBarApp\main.swift
Tests\FooBarLibTests\TestSomething.swift
Then in my Package.swift make sure FooBarApp depends on FooBarLib:
import PackageDescription
let package = Package(
name: "FooBar",
targets: [
.target(name: "FooBarLib"),
.target(name: "FooBarApp", dependencies: ["FooBarLib"])
],
)
Then in TestSomething.swift you import the FooBarLib module:
@testable import FooBarLib
import XCTest
class TestSomething: XCTestCase {
func testFunc() {
}
}