I try to run xctest in command line but I got the following error: cannot load underlying module for 'XCTest'
How are you trying to run your tests exactly? Please share the command you're using.
command line: swift filename.swift
XCTest
isn't part of Swift, it's in the Xcode toolchain. You'll have to set up an Xcode project and use xcodebuild
to run tests. You would end up with a command similar to this:
xcodebuild test -project MyAppProject.xcodeproj -scheme MyApp -destination 'platform=OS X,arch=x86_64'
See this link for more information on running tests from the command line
It is one of the core libraries. It is part of the Swift toolchain. It works on Linux too.
A package is simpler than an Xcode project. Then the command is just:
swift test
Using XCTest is not just a matter of linking its library; there are external things that need to be set up outside the module too. That additional work must be performed by the package manager, Xcode or some other helper tool. Is your aim just to test something, or to create such a tool?
Welp, I stand corrected. Sorry for spreading bad information