3

I have an iOS library with Swift package manager. I am trying to run unit tests with swift test The reason why I am not using xcodebuild is, I am trying to remove the .xcodeproj from my source control. Also, there is a warning when we create xcodeproj with spm, that generate-xcodeproj will be deprecated soon. TL;DR This library depends on Lottie I tried just running swift test in the root directory, but it gives lot of errors. like /.build/checkouts/lottie-ios/lottie-swift/src/Public/Animation/AnimationView.swift:859:11: error: cannot find 'superview' in scope I tried

swift test -Xswiftc "-sdk" -Xswiftc "`xcrun --sdk iphonesimulator --show-sdk-path`" -Xswiftc "-target" -Xswiftc "x86_64-apple-ios14.5-simulator"

Then it gives the error error: module 'XCTest' was created for incompatible target x86_64-apple-macos10.15. I did not specify macos10.15 anywhere, I am on macOS 11.5.1

I can build the package using the above command by replacing test with build. What is wrong with my test command?

As I understand this is because I am not specifying the target simulator, is it possible to specify the target simulator with swift test?

Johnykutty
  • 12,091
  • 13
  • 59
  • 100
  • Probably duplicate of: https://stackoverflow.com/questions/63765408 https://bugs.swift.org/browse/SR-13773 – Muhammed Kılıç Mar 07 '22 at 14:22
  • check my answer in this issue https://stackoverflow.com/questions/50754432/swift-build-on-terminal-throw-error-root-manifest-not-found/68863916#68863916 maybe helpful. – Maziar Saadatfar Mar 08 '22 at 06:00

1 Answers1

4

swift test only works for macOS testing. It does not support cross builds for iOS.

You do not need an existing Xcode project to use xcodebuild. Run the command, xcodebuild -list to initialize a Package.swift file for testing.

See the example here.

Paul Beusterien
  • 27,542
  • 6
  • 83
  • 139