# \[Solved\] Error "no such module 'Testing'" when tyring to use Swift Testing with CMake on Windows

**URL:** <https://forums.swift.org/t/solved-error-no-such-module-testing-when-tyring-to-use-swift-testing-with-cmake-on-windows/80780>\
**Category:** Using Swift\
**Tags:** windows, cmake, swift-testing\
**Created:** [June 29, 2025, 6:32pm UTC](https://forums.swift.org/t/solved-error-no-such-module-testing-when-tyring-to-use-swift-testing-with-cmake-on-windows/80780 "2025-06-29T18:32:30Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![ktraunmueller](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/ktraunmueller/32/46137_2.png) [@ktraunmueller](https://forums.swift.org/u/ktraunmueller)\
**Post date:** [June 29, 2025, 6:32pm UTC](https://forums.swift.org/t/solved-error-no-such-module-testing-when-tyring-to-use-swift-testing-with-cmake-on-windows/80780/1 "2025-06-29T18:32:30Z")

</div>

I am trying to use Swift Testing in my CMake-based Windows project setup, but the Testing module cannot be found:

```swift
[138/153] Building Swift Module 'WinTests' with 2 sources
FAILED: Tests/CMakeFiles/WinTests.dir/Common/Mouse/MouseEventAdapterTests.swift.obj Tests/CMakeFiles/WinTests.dir/main.swift.obj 
E:\Swift\Toolchains\0.0.0+Asserts\usr\bin\swiftc.exe -j 4 -num-threads 4 -c -module-name WinTests -g -Onone -use-ld=lld -Xlinker /DEBUG:FULL -Xlinker -debug:dwarf -diagnostic-style=llvm -Onone -g -swift-version 5 -incremental -parse-as-library -enable-experimental-feature Extern -output-file-map Tests\CMakeFiles\WinTests.dir\Debug\output-file-map.json E:/sandbox/ktraunmueller/compositor/Sources/Win/Tests/Common/Mouse/MouseEventAdapterTests.swift E:/sandbox/ktraunmueller/compositor/Sources/Win/Tests/main.swift
E:\sandbox\ktraunmueller\compositor\Sources\Win\Tests\Common\Mouse\MouseEventAdapterTests.swift:1:8: error: no such module 'Testing'
import Testing
       ^
E:\sandbox\ktraunmueller\compositor\Sources\Win\Tests\Common\Mouse\MouseEventAdapterTests.swift:1:8: error: no such module 'Testing'
import Testing
       ^

```

I am on a current 6.2 toolchain and want to use the bundled Testing framework (not a [separate download](https://github.com/swiftlang/swift-testing/blob/main/Documentation/CMake.md)).

I have read [this post](https://forums.swift.org/t/using-swift-testing-with-cmake/79651) and used it as a starting point. Here's the `CMakeLists.txt` for my `Tests` folder:

```swift
cmake_minimum_required(VERSION 3.29)
project(WinTests Swift)

file(GLOB_RECURSE TEST_SOURCES
    "${CMAKE_CURRENT_SOURCE_DIR}/*.swift"
)
add_executable(WinTests ${TEST_SOURCES})

set_target_properties(WinTests PROPERTIES
    SUFFIX .swift-testing
)

target_compile_options(WinTests PRIVATE 
    -parse-as-library 
)

target_link_libraries(WinTests PRIVATE
    Testing
)

# Enable CTest
enable_testing()
add_test(NAME WinTests COMMAND WinTests)

```

Swift toolchain ([20250629.2 TBC toolchain](https://github.com/thebrowsercompany/swift-build/releases/tag/20250629.2)):

```swift
compnerd.org Swift version 6.2-dev (LLVM f1607d165cb61ef, Swift a9f696b81261204)
Target: aarch64-unknown-windows-msvc
Build config: +assertions

```

Has anybody got this working on Windows?

thanks in advance

---

<div class="post-metadata">

**Author:** ![grynspan](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/grynspan/32/15315_2.png) [@grynspan](https://forums.swift.org/u/grynspan)\
**Post date:** [June 29, 2025, 7:10pm UTC](https://forums.swift.org/t/solved-error-no-such-module-testing-when-tyring-to-use-swift-testing-with-cmake-on-windows/80780/2 "2025-06-29T19:10:09Z")

</div>

As I mentioned in that thread, we don't support the use of CMake with Swift Testing. If you use Swift Package Manager, is it able to find the Testing module?

@plemarquand FYI.

---

<div class="post-metadata">

**Author:** ![compnerd](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/compnerd/32/2165_2.png) [@compnerd](https://forums.swift.org/u/compnerd)\
**Post date:** [June 29, 2025, 9:17pm UTC](https://forums.swift.org/t/solved-error-no-such-module-testing-when-tyring-to-use-swift-testing-with-cmake-on-windows/80780/3 "2025-06-29T21:17:28Z")

</div>

> [@ktraunmueller](#):
>
> Has anybody got this working on Windows?

This should work fine. Did you adjust the library search path for the developer libraries?

---

<div class="post-metadata">

**Author:** ![ktraunmueller](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/ktraunmueller/32/46137_2.png) [@ktraunmueller](https://forums.swift.org/u/ktraunmueller)\
**Post date:** [June 30, 2025, 6:07am UTC](https://forums.swift.org/t/solved-error-no-such-module-testing-when-tyring-to-use-swift-testing-with-cmake-on-windows/80780/4 "2025-06-30T06:07:37Z")

</div>

I had tried adding this function here

```swift
function(enable_swift_testing target)
    # Locate Swift compiler
    find_program(SWIFT_EXECUTABLE swiftc)
    if(NOT SWIFT_EXECUTABLE)
        message(FATAL_ERROR "Swift compiler (swiftc) not found in PATH.")
    endif()

    # Get Swift target info in JSON format
    execute_process(
        COMMAND ${SWIFT_EXECUTABLE} -print-target-info
        OUTPUT_VARIABLE SWIFT_TARGET_INFO_JSON
        ERROR_QUIET
        OUTPUT_STRIP_TRAILING_WHITESPACE
    )

    # Extract runtime library path
    string(JSON SWIFT_LIB_PATH GET ${SWIFT_TARGET_INFO_JSON} "paths" "runtimeLibraryPaths" 0)

    # set(SWIFT_LIB_PATH "E:/Swift/Platforms/0.0.0/Windows.platform/Developer/Library/Testing-0.0.0/usr/lib/swift/windows")

    if(NOT EXISTS "${SWIFT_LIB_PATH}/Testing.swiftmodule")
        message(WARNING "Testing.swiftmodule not found at: ${SWIFT_LIB_PATH}")
    else()
        message(STATUS "Swift Testing.swiftmodule found at: ${SWIFT_LIB_PATH}")
    endif()

    # Apply to the given target
    target_compile_options(${target} PRIVATE -I"${SWIFT_LIB_PATH}")
    target_link_directories(${target} PRIVATE "${SWIFT_LIB_PATH}")
    target_link_libraries(${target} PRIVATE Testing)
endfunction()

```

to my `CMakeLists.txt`

```swift
cmake_minimum_required(VERSION 3.29)
project(WinTests Swift)

include(FindSwiftTesting)

file(GLOB_RECURSE TEST_SOURCES
    "${CMAKE_CURRENT_SOURCE_DIR}/*.swift"
)
add_executable(WinTests ${TEST_SOURCES})

set_target_properties(WinTests PROPERTIES
    SUFFIX .swift-testing
)

enable_swift_testing(WinTests)

target_compile_options(WinTests PRIVATE 
    -parse-as-library 
    -enable-experimental-feature Extern
)

target_link_libraries(WinTests PRIVATE
Testing
# CompositorCore
# CWinRT
# UWP
# Win2D
# WinAppSDK
# WindowsFoundation
# WinUI
)

# Enable CTest
enable_testing()
add_test(NAME WinTests COMMAND WinTests)

```

but that didn't improve things.

I also tried hardwiring

```swift
    set(SWIFT_LIB_PATH "E:/Swift/Platforms/0.0.0/Windows.platform/Developer/Library/Testing-0.0.0/usr/lib/swift/windows")

```

in the function, but that made no difference.

---

<div class="post-metadata">

**Author:** ![compnerd](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/compnerd/32/2165_2.png) [@compnerd](https://forums.swift.org/u/compnerd)\
**Post date:** [June 30, 2025, 6:09am UTC](https://forums.swift.org/t/solved-error-no-such-module-testing-when-tyring-to-use-swift-testing-with-cmake-on-windows/80780/5 "2025-06-30T06:09:54Z")

</div>

> [@ktraunmueller](#):
>
> ```swift
> # set(SWIFT_LIB_PATH "E:/Swift/Platforms/0.0.0/Windows.platform/Developer/Library/Testing-0.0.0/usr/lib/swift/windows")
> 
> ```

Are you building the toolchain yourself? That path does not seem correct for recent releases.

Try `$ENV{SDKROOT}/../../Library/Testing-0.0.0/usr/lib/swift/windows/x86_64`.

---

<div class="post-metadata">

**Author:** ![ktraunmueller](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/ktraunmueller/32/46137_2.png) [@ktraunmueller](https://forums.swift.org/u/ktraunmueller)\
**Post date:** [June 30, 2025, 7:55am UTC](https://forums.swift.org/t/solved-error-no-such-module-testing-when-tyring-to-use-swift-testing-with-cmake-on-windows/80780/6 "2025-06-30T07:55:44Z")

</div>

I am using yesterday's TBC toolchain build.

The relative path you gave and the hardcoded path I tried expand to the same path:

```swift
set(SDKROOT $ENV{SDKROOT})
set(RELATIVE_PATH "${SDKROOT}/../../Library/Testing-0.0.0/usr/lib/swift/windows")
file(REAL_PATH "${RELATIVE_PATH}" SWIFT_LIB_PATH)
message(STATUS "SWIFT_LIB_PATH: ${SWIFT_LIB_PATH}")

```

outputs

```swift
[cmake] -- SWIFT_LIB_PATH: E:/Swift/Platforms/0.0.0/Windows.platform/Developer/Library/Testing-0.0.0/usr/lib/swift/windows

```

My modified `enable_swift_testing` function with `$ENV{SDKROOT}` now looks like this:

```swift
function(enable_swift_testing target)
    set(RELATIVE_PATH "$ENV{SDKROOT}/../../Library/Testing-0.0.0/usr/lib/swift/windows")
    file(REAL_PATH "${RELATIVE_PATH}" SWIFT_TESTING_LIB_PATH)

    if(NOT EXISTS "${SWIFT_TESTING_LIB_PATH}/Testing.swiftmodule")
        message(WARNING "Testing.swiftmodule not found at: ${SWIFT_TESTING_LIB_PATH}")
    else()
        message(STATUS "Testing.swiftmodule found at: ${SWIFT_TESTING_LIB_PATH}")
    endif()

    target_compile_options(${target} PRIVATE -I"${SWIFT_TESTING_LIB_PATH}")
    target_link_directories(${target} PRIVATE "${SWIFT_TESTING_LIB_PATH}/aarch64")
    target_link_libraries(${target} PRIVATE Testing)
endfunction()

```

I added the architecture folder only on the `target_link_directories` call, because I am guessing that the `Testing.swiftmodule` needs to be on the include path (`-I"${SWIFT_LIB_PATH}"`) and the .lib for the target platform needs to be in the `target_link_directories` list:

```swift
|-- Platforms
| `-- 0.0.0
| `-- Windows.platform
| |-- Developer
| | |-- Library
| | | |-- Testing-0.0.0
| | | | `-- usr
| | | | |-- bin32
| | | | | |-- Testing.dll
| | | | | `-- _Testing_Foundation.dll
| | | | |-- bin64
| | | | | |-- Testing.dll
| | | | | `-- _Testing_Foundation.dll
| | | | |-- bin64a
| | | | | |-- Testing.dll
| | | | | `-- _Testing_Foundation.dll
| | | | `-- lib
| | | | `-- swift
| | | | `-- windows
| | | | |-- Testing.swiftcrossimport
| | | | | `-- Foundation.swiftoverlay
| | | | |-- Testing.swiftmodule
| | | | | |-- aarch64-unknown-windows-msvc.swiftdoc
| | | | | |-- aarch64-unknown-windows-msvc.swiftinterface
| | | | | |-- i686-unknown-windows-msvc.swiftdoc
| | | | | |-- i686-unknown-windows-msvc.swiftinterface
| | | | | |-- x86_64-unknown-windows-msvc.swiftdoc
| | | | | `-- x86_64-unknown-windows-msvc.swiftinterface
| | | | |-- _Testing_Foundation.swiftmodule
| | | | | |-- aarch64-unknown-windows-msvc.swiftdoc
| | | | | |-- aarch64-unknown-windows-msvc.swiftinterface
| | | | | |-- i686-unknown-windows-msvc.swiftdoc
| | | | | |-- i686-unknown-windows-msvc.swiftinterface
| | | | | |-- x86_64-unknown-windows-msvc.swiftdoc
| | | | | `-- x86_64-unknown-windows-msvc.swiftinterface
| | | | |-- aarch64
| | | | | |-- Testing.lib
| | | | | `-- _Testing_Foundation.lib
| | | | |-- i686
| | | | | |-- Testing.lib
| | | | | `-- _Testing_Foundation.lib
| | | | `-- x86_64
| | | | |-- Testing.lib
| | | | `-- _Testing_Foundation.lib

```

_Also: Thanks for the quick response (as always)!_

---

<div class="post-metadata">

**Author:** ![compnerd](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/compnerd/32/2165_2.png) [@compnerd](https://forums.swift.org/u/compnerd)\
**Post date:** [June 30, 2025, 4:44pm UTC](https://forums.swift.org/t/solved-error-no-such-module-testing-when-tyring-to-use-swift-testing-with-cmake-on-windows/80780/7 "2025-06-30T16:44:21Z")

</div>

> [@ktraunmueller](#):
>
> I added the architecture folder only on the `target_link_directories` call, because I am guessing that the `Testing.swiftmodule` needs to be on the include path (`-I"${SWIFT_LIB_PATH}"`) and the .lib for the target platform needs to be in the `target_link_directories` list:

Yes, that is correct, the `.swiftmodule` needs to be in the module search path (`-I`) and the `.lib` files need to be in the linker search path (`-L`). Once the import is resolved, the linker search path will become relevant.

Is the module not found after that adjustment? Can you re-run the build with `-D CMAKE_Swift_FLAGS="-Rmodule-loading"`? That should help identify what is going on with the module search.

---

<div class="post-metadata">

**Author:** ![ktraunmueller](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/ktraunmueller/32/46137_2.png) [@ktraunmueller](https://forums.swift.org/u/ktraunmueller)\
**Post date:** [June 30, 2025, 4:58pm UTC](https://forums.swift.org/t/solved-error-no-such-module-testing-when-tyring-to-use-swift-testing-with-cmake-on-windows/80780/8 "2025-06-30T16:58:22Z")

</div>

I think this here should be the relevant part of the build output after adding `-Rmodule-loading` to my `CMAKE_Swift_FLAGS`:

```swift
...
[136/153] E:\Swift\Toolchains\0.0.0+Asserts\usr\bin\swiftc.exe -j 4 -num-threads 4 -c -module-name WinTests -g -Onone -use-ld=lld -Xlinker /DEBUG:FULL -Xlinker -debug:dwarf -diagnostic-style=llvm -Rmodule-loading -Onone -g -swift-version 5 -incremental -I\"E:/Swift/Platforms/0.0.0/Windows.platform/Developer/Library/Testing-0.0.0/usr/lib/swift/windows\" -parse-as-library -enable-experimental-feature Extern -output-file-map Tests\CMakeFiles\WinTests.dir\Debug\output-file-map.json E:/sandbox/ktraunmueller/compositor/Sources/Win/Tests/Common/Mouse/MouseEventAdapterTests.swift E:/sandbox/ktraunmueller/compositor/Sources/Win/Tests/main.swift
FAILED: Tests/CMakeFiles/WinTests.dir/Common/Mouse/MouseEventAdapterTests.swift.obj Tests/CMakeFiles/WinTests.dir/main.swift.obj
E:\Swift\Toolchains\0.0.0+Asserts\usr\bin\swiftc.exe -j 4 -num-threads 4 -c -module-name WinTests -g -Onone -use-ld=lld -Xlinker /DEBUG:FULL -Xlinker -debug:dwarf -diagnostic-style=llvm -Rmodule-loading -Onone -g -swift-version 5 -incremental -I\"E:/Swift/Platforms/0.0.0/Windows.platform/Developer/Library/Testing-0.0.0/usr/lib/swift/windows\" -parse-as-library -enable-experimental-feature Extern -output-file-map Tests\CMakeFiles\WinTests.dir\Debug\output-file-map.json E:/sandbox/ktraunmueller/compositor/Sources/Win/Tests/Common/Mouse/MouseEventAdapterTests.swift E:/sandbox/ktraunmueller/compositor/Sources/Win/Tests/main.swift
Module import search paths:
  [0] (non-system) "E:\Swift\Platforms\0.0.0\Windows.platform\Developer\Library\Testing-0.0.0\usr\lib\swift\windows"
Framework search paths:
Implicit framework search paths:
Runtime library import search paths:
  [0] E:\Swift\Toolchains\0.0.0+Asserts\usr\lib\swift\windows
  [1] E:\Swift\Toolchains\0.0.0+Asserts\usr\lib\swift\windows\aarch64
  [2] E:\Swift\Platforms\0.0.0\Windows.platform\Developer\SDKs\Windows.sdk\usr\lib\swift\windows
  [3] E:\Swift\Platforms\0.0.0\Windows.platform\Developer\SDKs\Windows.sdk\usr\lib\swift\windows\aarch64
(End of search path lists.)
<unknown>:0: remark: 'Swift' has a required transitive dependency on 'SwiftShims'
<unknown>:0: remark: loaded module 'SwiftShims'; source: 'E:\Swift\Platforms\0.0.0\Windows.platform\Developer\SDKs\Windows.sdk\usr\lib\swift\shims\module.modulemap', loaded: 'C:\Users\karl\AppData\Local\clang\ModuleCache\1XXETTPEZDFIH\SwiftShims-3QCGUQPGZBKD0.pcm'
<unknown>:0: remark: loaded module 'Swift'; source: 'E:\Swift\Platforms\0.0.0\Windows.platform\Developer\SDKs\Windows.sdk\usr\lib\swift\windows\Swift.swiftmodule\aarch64-unknown-windows-msvc.swiftinterface', loaded: 'E:\Swift\Platforms\0.0.0\Windows.platform\Developer\SDKs\Windows.sdk\usr\lib\swift\windows\Swift.swiftmodule\aarch64-unknown-windows-msvc.swiftmodule'
<unknown>:0: remark: '_StringProcessing' has a required transitive dependency on 'Swift'
<unknown>:0: remark: loaded module '_StringProcessing'; source: 'E:\Swift\Platforms\0.0.0\Windows.platform\Developer\SDKs\Windows.sdk\usr\lib\swift\windows\_StringProcessing.swiftmodule\aarch64-unknown-windows-msvc.swiftinterface', loaded: 'C:\Users\karl\AppData\Local\clang\ModuleCache\_StringProcessing-1XXI22SV15PNA.swiftmodule'
<unknown>:0: remark: loaded module '_SwiftConcurrencyShims'; source: 'E:\Swift\Platforms\0.0.0\Windows.platform\Developer\SDKs\Windows.sdk\usr\lib\swift\shims\module.modulemap', loaded: 'C:\Users\karl\AppData\Local\clang\ModuleCache\1XXETTPEZDFIH\_SwiftConcurrencyShims-3QCGUQPGZBKD0.pcm'
<unknown>:0: remark: '_Concurrency' has a required transitive dependency on 'Swift'
<unknown>:0: remark: '_Concurrency' has a required transitive dependency on 'SwiftShims'
<unknown>:0: remark: loaded module '_Concurrency'; source: 'E:\Swift\Platforms\0.0.0\Windows.platform\Developer\SDKs\Windows.sdk\usr\lib\swift\windows\_Concurrency.swiftmodule\aarch64-unknown-windows-msvc.swiftinterface', loaded: 'C:\Users\karl\AppData\Local\clang\ModuleCache\_Concurrency-2OL061KBKSHQC.swiftmodule'
<unknown>:0: remark: 'SwiftOnoneSupport' has a required transitive dependency on 'Swift'
<unknown>:0: remark: loaded module 'SwiftOnoneSupport'; source: 'E:\Swift\Platforms\0.0.0\Windows.platform\Developer\SDKs\Windows.sdk\usr\lib\swift\windows\SwiftOnoneSupport.swiftmodule\aarch64-unknown-windows-msvc.swiftinterface', loaded: 'C:\Users\karl\AppData\Local\clang\ModuleCache\SwiftOnoneSupport-29BN42HHB1KCZ.swiftmodule'
E:\sandbox\ktraunmueller\compositor\Sources\Win\Tests\Common\Mouse\MouseEventAdapterTests.swift:2:8: error: no such module 'Testing'      
import Testing

```

---

<div class="post-metadata">

**Author:** ![compnerd](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/compnerd/32/2165_2.png) [@compnerd](https://forums.swift.org/u/compnerd)\
**Post date:** [June 30, 2025, 5:00pm UTC](https://forums.swift.org/t/solved-error-no-such-module-testing-when-tyring-to-use-swift-testing-with-cmake-on-windows/80780/9 "2025-06-30T17:00:46Z")

</div>

I think that the issue is that you have extra quotes in your path. Use `"-I..."` rather than `-I\"...\"`.

---

<div class="post-metadata">

**Author:** ![ktraunmueller](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/ktraunmueller/32/46137_2.png) [@ktraunmueller](https://forums.swift.org/u/ktraunmueller)\
**Post date:** [June 30, 2025, 5:09pm UTC](https://forums.swift.org/t/solved-error-no-such-module-testing-when-tyring-to-use-swift-testing-with-cmake-on-windows/80780/10 "2025-06-30T17:09:18Z")

</div>

Yes, that now successully produces the test binary:

```swift
E:\sandbox\ktraunmueller\compositor\Sources\Win\build\Tests>dir
...
06/30/2025 07:03 PM 1,426 WinTests.lib
06/30/2025 07:03 PM 483,328 WinTests.pdb
06/30/2025 07:03 PM 94,208 WinTests.swift-testing

```

Thank you so much 🙏
