When running WASM tests with swift-build, tests using the Swift Testing framework (import Testing) are not being discovered and executed, resulting in "0 tests" output:
Searching for Wasm test binaries...
Found test binaries:
.build/wasm32-unknown-wasip1/debug/MistKitPackageTests.xctest
Running tests with WasmKit: .build/wasm32-unknown-wasip1/debug/MistKitPackageTests.xctest
Test Suite 'All tests' started at 1970-01-01 00:03:45.952
Test Suite 'debug.xctest' started at 1970-01-01 00:03:46.013
Test Suite 'debug.xctest' passed at 1970-01-01 00:03:46.014
Executed 0 tests, with 0 failures (0 unexpected) in 0.0 (0.0) seconds
The action currently runs WASM test binaries without specifying the testing library:
wasmkit run MistKitPackageTests.xctestHowever, Swift Testing tests on WASM require an explicit flag:
wasmkit run MistKitPackageTests.xctest -- --testing-library swift-testingWhen this flag is provided, tests execute correctly:
◇ Test run started.
↳ Testing Library Version: 6.2.3 (48a471ab313e858)
↳ Target Platform: wasm32-unknown-wasip
◇ Suite "Token Manager - Authentication Method" started.
✔ Test "AuthenticationMethod computed properties" passed after 0.016 seconds.
...
Test run with 487 tests passed after 28.891 seconds.
Unlike native platforms where Swift Package Manager auto-detects the testing framework, WASM requires explicit specification:
- Swift Testing tests (
@Test,@Suite): Require--testing-library swift-testing - XCTest tests (
XCTestCasesubclasses): Run without flag or with--testing-library xctest - Mixed tests: Currently problematic on WASM (would require multiple test runs)
Reference: Swift Testing WASI Documentation
Add automatic testing framework detection with an optional override parameter.
inputs:
wasm-testing-library:
description: 'Testing framework for WASM tests (auto, swift-testing, xctest, both)'
required: false
default: 'auto'
wasm-swift-test-flags:
description: 'Additional flags to pass to WASM test runner'
required: falseWhen wasm-testing-library: 'auto' (default):
-
Scan test sources for imports:
# Check for Swift Testing grep -r "import Testing" Tests/ --include="*.swift" -q HAS_SWIFT_TESTING=$? # Check for XCTest grep -r "import XCTest" Tests/ --include="*.swift" -q HAS_XCTEST=$?
-
Determine testing library:
- If only Swift Testing found → Use
--testing-library swift-testing - If only XCTest found → Use
--testing-library xctest(or no flag) - If both found → Use
bothmode (run twice) - If neither found → Use
--testing-library swift-testing(Swift 6+ default)
- If only Swift Testing found → Use
-
Execute tests accordingly:
case $TESTING_LIBRARY in swift-testing) wasmkit run $TEST_BINARY -- --testing-library swift-testing ;; xctest) wasmkit run $TEST_BINARY -- --testing-library xctest ;; both) echo "Running Swift Testing tests..." wasmkit run $TEST_BINARY -- --testing-library swift-testing echo "Running XCTest tests..." wasmkit run $TEST_BINARY -- --testing-library xctest ;; esac
For projects that know their testing framework:
# Force Swift Testing
- uses: brightdigit/swift-build@1.5.0-beta.2
with:
type: wasm
wasm-testing-library: swift-testing
# Force XCTest
- uses: brightdigit/swift-build@1.5.0-beta.2
with:
type: wasm
wasm-testing-library: xctest
# Force both (run twice)
- uses: brightdigit/swift-build@1.5.0-beta.2
with:
type: wasm
wasm-testing-library: both
# Pass additional test flags
- uses: brightdigit/swift-build@1.5.0-beta.2
with:
type: wasm
wasm-swift-test-flags: --filter "TestSuiteName"Instead of scanning sources, parse Package.swift for test target dependencies:
.testTarget(
name: "MyTests",
dependencies: ["MyPackage", "Testing"] // Swift Testing
)
.testTarget(
name: "MyTests",
dependencies: ["MyPackage", "XCTest"] // XCTest
)This approach is more reliable but requires parsing Swift code or running SPM commands.
- Backward compatible: Default
automode works for existing projects - Zero configuration: Automatically detects and uses correct framework
- Future-proof: Supports mixed testing scenarios
- Performance: Can skip tests with explicit
wasm-testing-library: none - Flexibility: Manual override for edge cases
- Add new input parameters to
action.yml - Implement testing framework detection logic
- Update WASM test execution script to pass appropriate flags
- Add tests for auto-detection (Swift Testing, XCTest, mixed, none)
- Update README with new parameters and examples
- Add migration guide for existing users
- Consider adding warning when mixed tests detected
- #72: Swap Wasmtime for WasmKit (completed)
- #30: Add WASM Support (foundation)
- #68: WASM code coverage is not supported (separate concern)
This issue was discovered while testing MistKit which uses Swift Testing exclusively. The tests work correctly when run manually with:
swift build --swift-sdk swift-6.2.3-RELEASE_wasm --build-tests \
-Xcc -D_WASI_EMULATED_SIGNAL \
-Xcc -D_WASI_EMULATED_MMAN \
-Xlinker -lwasi-emulated-signal \
-Xlinker -lwasi-emulated-mman
wasmkit run .build/wasm32-unknown-wasip1/debug/MistKitPackageTests.xctest -- --testing-library swift-testingResult: All 487 tests pass successfully.
- Swift Testing became the default testing framework in Swift 6.0
- Many modern projects are migrating from XCTest to Swift Testing
- WASM support is critical for cross-platform Swift development
- This issue affects any project using Swift Testing with WASM builds
- Is source scanning an acceptable approach, or would you prefer Package.swift parsing?
- Should the default be
autoor require explicit configuration? - For mixed tests, should we run both or fail with an error message?
- Should we emit a GitHub Actions warning when mixed tests are detected?
Environment:
- swift-build: 1.5.0-beta.2
- Swift: 6.2.3
- WasmKit: 0.1.6
- Platform: Ubuntu (GitHub Actions)