Running unit tests from the command line with xcodebuild

Previously, we discussed how Xcode 9.4.1 cannot run unit tests for Frameworks on macOS Mojave. I mentioned there that the workaround is to run unit tests from the command line, and a reader wrote in to ask how to do that. Here’s the xcodebuild command for one of my projects:

xcodebuild clean test -project Repos.xcodeproj -scheme "Repos" -destination "name=iPhone X,OS=12.1"

I always like to run clean first since I’ve seen so many issues that are easily resolved with a clean. The test subcommand tells it to run your unit tests in the given scheme. And finally, the destination here tells it to run in the iPhone X simulator running iOS 12.1.

If you’re using an xcworkspace rather than an xcodeproj, you can replace the -project part with -workspace and give it the name of your workspace instead. Happy testing!

How should you start unit testing your app?

Unit testing for iOS can be lonely — most iOS developers don't seem to be doing it. Should you be writing unit tests? What are the benefits of unit testing, anyway? And if it is worth the effort, how do you get started? Enter your name and email in the boxes to get answers to your questions.

We won't send you spam. Unsubscribe at any time. Powered by ConvertKit