Reputation: 881
I am building a Swift Package library that provide some UI components, for both macOS and iOS.
I would like to be able to test this codebase and cover my code with unit test for both platforms.
Is there a way to manage that ?
Upvotes: 7
Views: 1644
Reputation: 1
In 2024 the Swift package doesn't have the ability to run app (UI) on its own (unlike Flutter where it's possible).
The best approach is to add a .xcworkspace
and an app separately inside the root folder of the package, link both package and the app inside the workspace, then link the package to the app.
This is the best approach because package.swift
should be ideally kept in the root folder for Swift Package Manager to detect it once you publish in a repository.
YourPackage/
│
├── Package.swift # Swift Package manifest
├── README.md # Documentation for the package
├── LICENSE # License (optional)
├── Sources/ # Swift Package source code
│ └── YourLibrary/
│ └── YourFile.swift
├── Tests/ # Swift Package unit tests
│ └── YourLibraryTests/
│ └── YourLibraryTests.swift
├── ExampleApp/ # Example app to showcase the package
│ ├── ExampleApp.xcodeproj # Xcode project for the example app
│ └── ExampleApp/ # App's source files
│ ├── AppDelegate.swift
│ ├── ContentView.swift
│ └── Info.plist
└── YourPackage.xcworkspace # Workspace to m`enter code here`anage both the package and example app
Upvotes: 0
Reputation: 16921
As of Swift 5.4, the Swift Package Manager doesn't provide that functionality out of the box.
To carry out UI tests, you need to create a separate app (in its separate xcode project), whose only purpose is to import the package and run UI tests via xcodebuild
commands (as swift test
won't work).
Upvotes: 2