# I made a little SwiftPM Package that uses UIKit. How can I run tests from command line

**URL:** <https://forums.swift.org/t/i-made-a-little-swiftpm-package-that-uses-uikit-how-can-i-run-tests-from-command-line/50399>\
**Category:** Using Swift\
**Tags:** uikit, packagemanager, testing, xctest\
**Created:** [July 13, 2021, 7:55am UTC](https://forums.swift.org/t/i-made-a-little-swiftpm-package-that-uses-uikit-how-can-i-run-tests-from-command-line/50399 "2021-07-13T07:55:45Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![nacho4d](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/nacho4d/32/6504_2.png) [@nacho4d](https://forums.swift.org/u/nacho4d)\
**Post date:** [July 13, 2021, 7:55am UTC](https://forums.swift.org/t/i-made-a-little-swiftpm-package-that-uses-uikit-how-can-i-run-tests-from-command-line/50399/1 "2021-07-13T07:55:45Z")

</div>

Hello swift community

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
xcodebuild -scheme MyLittleViewUtil build -destination "platform=iOS Simulator,name=iPhone 8,OS=latest"

xcodebuild -scheme MyLittleViewUtil test -destination "platform=iOS Simulator,name=iPhone 8,OS=latest"

```

## Questions:

1. What is the correct command to run something similar to above but from SPM command line?

For building this works:

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

```

But for testing it fails:

```swift
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:

1. 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?

Any help is appreciated.

---

<div class="post-metadata">

**Author:** ![ole](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/ole/32/18720_2.png) [@ole](https://forums.swift.org/u/ole)\
**Post date:** [July 13, 2021, 9:03am UTC](https://forums.swift.org/t/i-made-a-little-swiftpm-package-that-uses-uikit-how-can-i-run-tests-from-command-line/50399/2 "2021-07-13T09:03:43Z")

</div>

`xcodebuild` can build/test SwiftPM packages directly, without an Xcode project.

In your package directory, run `xcodebuild -list` to see the available "schemes" for your package.

Then run `xcodebuild` as if the package were an Xcode project:

```swift
xcodebuild -scheme MyLittleViewUtil test -destination "platform=iOS Simulator,name=iPhone 8,OS=latest"

```

---

<div class="post-metadata">

**Author:** ![nacho4d](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/nacho4d/32/6504_2.png) [@nacho4d](https://forums.swift.org/u/nacho4d)\
**Post date:** [July 13, 2021, 10:10am UTC](https://forums.swift.org/t/i-made-a-little-swiftpm-package-that-uses-uikit-how-can-i-run-tests-from-command-line/50399/3 "2021-07-13T10:10:06Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![SDGGiesbrecht](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/sdggiesbrecht/32/4768_2.png) [@SDGGiesbrecht](https://forums.swift.org/u/SDGGiesbrecht)\
**Post date:** [July 13, 2021, 8:22pm UTC](https://forums.swift.org/t/i-made-a-little-swiftpm-package-that-uses-uikit-how-can-i-run-tests-from-command-line/50399/4 "2021-07-13T20:22:42Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Ignacio\_Soto](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/ignacio_soto/32/396_2.png) [@Ignacio\_Soto](https://forums.swift.org/u/Ignacio_Soto)\
**Post date:** [July 14, 2023, 4:43pm UTC](https://forums.swift.org/t/i-made-a-little-swiftpm-package-that-uses-uikit-how-can-i-run-tests-from-command-line/50399/5 "2023-07-14T16:43:36Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![nicholaslythall](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/nicholaslythall/32/11971_2.png) [@nicholaslythall](https://forums.swift.org/u/nicholaslythall)\
**Post date:** [February 15, 2024, 3:52am UTC](https://forums.swift.org/t/i-made-a-little-swiftpm-package-that-uses-uikit-how-can-i-run-tests-from-command-line/50399/7 "2024-02-15T03:52:59Z")

</div>

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:

```swift
xcodebuild -workspace MyProject.xcworkspace -list

```
