I am trying to decompose my big iOS app into small packages. In the process of it, I found some problems when trying to test SPM with iOS specific (UIKit) stuff in it.
I have made one small SPM Package library and added it as a local package into my project. I see that now an additional scheme is available in my Xcode project.
I can successfully build via Xcode UI and also with command line:
swift test -Xswiftc "-sdk" -Xswiftc "`xcrun --sdk iphonesimulator --show-sdk-path`" -Xswiftc "-target" -Xswiftc "x86_64-apple-ios14.0-simulator"
error: module 'XCTest' was created for incompatible target x86_64-apple-macos10.15:
My little library uses UIKit and some UIViews. I have heard that for now SPM tests cannot run on an host application. Is there anything I can do to test the UI from SPM only? Is Xcode13/Swift/SPM functionality enhanced in anyway that alleviate my situation? What are my alternatives?
Thank you. I didn't know that command was ok without an Xcode project. !
Do you know if there is an equivalent swift test ... command that at least compiles and try to run the tests? (I know that probably not all tests will succeed because I don't have a proper UIView in hierarchy etc)
There is no equivalent command. Raw SwiftPM only officially supports builds for the host platform. It has no notion of simulators or separate devices. xcodebuild is the correct tool for the job.
Unfortunately this doesn't work if the same folder containing Package.swift also has an Xcode project with schemes. xcodebuild -list only picks ups those schemes and not any additional targets in the package.
If the Package.swift and the Xcode project are in the same folder but you also have them added to the same workspace you can use the -workspace option and it will list the schemes for both: