Swift testing with SwiftPM using Xcode 16 (and Swift 6)

Hey,
I just saw the new testing library in the latest WWDC video, so I created a new Swift Package using the builtin template of Xcode 16, added #expect(false) and executed swift test.
Unfortunately, the tests aren't executed. Did I miss something or is there no SPM support yet? It does work using Xcode.

// swift-tools-version: 6.0

import PackageDescription

let package = Package(
    name: "MyLibrary",
    platforms: [.macOS(.v15), .iOS(.v14), .tvOS(.v14), .watchOS(.v10)],
    products: [
        .library(
            name: "MyLibrary",
            targets: ["MyLibrary"]),
    ],
    targets: [
        .target(
            name: "MyLibrary"),
        .testTarget(
            name: "MyLibraryTests",
            dependencies: ["MyLibrary"]
        ),
    ]
)
import Testing
@testable import MyLibrary

@Test func example() async throws {
    #expect(false)
}

Output of swift test:

Test Suite 'All tests' started at 2024-06-11 22:01:32.098.
Test Suite 'All tests' passed at 2024-06-11 22:01:32.099.
	 Executed 0 tests, with 0 failures (0 unexpected) in 0.000 (0.001) seconds

This is a known issue with the version of Swift Package Manager included with Xcode 16 Beta 1.

To work around it, pass --enable-swift-testing to the swift test command.

2 Likes

Thank you! I just noticed, the bottom line still shows:

✘ Test example() failed after 0.001 seconds with 1 issue.
✘ Test run with 1 test failed after 0.001 seconds with 1 issue.
Building for debugging...
[3/3] Linking MyLibraryPackageTests
Build complete! (0.39s)
Test Suite 'All tests' started at 2024-06-11 23:33:47.473.
Test Suite 'All tests' passed at 2024-06-11 23:33:47.474.
	 Executed 0 tests, with 0 failures (0 unexpected) in 0.000 (0.001) seconds

Is this (the last line) also a known bug and tracked internally?

1 Like

Do you mean this line?

Executed 0 tests, with 0 failures (0 unexpected) in 0.000 (0.001) seconds

That line is expected because it's emitted by XCTest and is referring to XCTest content specifically. Swift Testing runs first, finishes, then XCTest runs. Neither library is aware of output from the other.

Could I ask you to use Apple's
Feedback Assistant to file feedback letting Apple know the output is confusing? Let me know the FB number here and I'll make sure we investigate further. Thanks!

1 Like

Here you are: 13862097

2 Likes