xcodebuild equivalent of Xcode's "Product > Build For > Testing" - ios

I'm trying to write a script that submits iOS apps to AppThwack (a 'real device' UI testing service). Their guidance is to use the Xcode GUI and build the app using the Build For > Testing option in the Xcode Product menu. This works, but I haven't been able to translate this into the xcodebuild equivalent.
More generally, how do we determine what arguments Xcode is passing to xcodebuild (assuming it uses that tool).

This is now possible as of Xcode 8 (in beta at time of writing). Use build-for-testing.
Example:
xcodebuild -workspace <workspace> -scheme <scheme> -destination 'generic/platform=iOS' build-for-testing
To switch to a beta version of xcodebuild, use xcode-select:
sudo xcode-select -switch /Applications/Xcode-beta.app/Contents/Developer

xctool has a flag called build-tests that will do just that.
(As of this post, it is not currently Xcode 7 compatible, but they are working on it.)

Related

How to test a Swift Package, that uses UIKit?

I've created my first Swift Package recently. It's only used in iOS currently, and if it goes anywhere else, it might be on tvOS, but that would be it.
I was having trouble getting UIKit to be used. And I saw this note over here, and that really helped solve my problem:
https://stackoverflow.com/a/58684636/1435520
The command I used (and mentioned above) is this:
swift build -Xswiftc "-sdk" -Xswiftc "`xcrun --sdk iphonesimulator --show-sdk-path`" -Xswiftc "-target" -Xswiftc "x86_64-apple-ios13.0-simulator"
However, I'd really like to have unit tests. Running swift test... with the same arguments mentioned for swift build. But then that gives me a new error:
error: module 'XCTest' was created for incompatible target x86_64-apple-macos10.14
So, I guess I'm just wondering if it's possible to do this. Like, how could I create a Swift Package, that uses UIKit, and have it be testable?
I've been using the command xcodebuild as detailed in this forum post, which requires you to also generate a .xcodeproj:
swift package generate-xcodeproj
xcodebuild build -sdk iphoneos -scheme 'MyPackage-Package'
xcodebuild test -destination 'name=iPhone 11' -scheme 'MyPackage-Package'
But if you're using SPM Resources, you'll run into issues as I detailed here: https://bugs.swift.org/browse/SR-13773
I have spent a lot of time trying to run tests of some complex framework. None of the solutions have worked for me.
I found out that generate-xcodeproj is marked as deprecated.
The reason to that I have found here.
"... starting Xcode 11, opening and building packages is directly supported by Xcode ..."
So I run xcodebuild test directly in the package folder, without creating the xcodeproj.
xcodebuild -scheme '<package name>-Package' -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPad Air (4th generation),OS=15.0' test
And it have worked.
I was trying to build and test my internal packages on CI, nothing works for me, and generating an xcodeproj will be deprecated in the future.
What works for me is to just specify the target as macOS 10.15 by doing this without anything else:
swift test -Xswiftc -target -Xswiftc x86_64-apple-macosx10.15

XCode 6 Unit Testing Without Building

Is there a way to prevent the app from building when I am just unit testing? When I run the test it builds the app and that takes minutes. I have written the tests in Swift and targets ios 8.
In Xcode 8+, you can pass the "test-without-building" option.
$ xcodebuild -workspace <your_xcworkspace> -scheme <your_scheme> -sdk iphonesimulator -destination ‘platform=iOS Simulator,name=<your_simulator>,OS=10.2’ test-without-building
Read more here: https://medium.com/xcblog/speed-up-ios-ci-using-test-without-building-xctestrun-and-fastlane-a982b0060676

xcodebuild doesn't show all compile errors?

There are 2 compile errors in my project(Display in XCode).
But when I use xcodebuild to compile the project in terminal, only one compile error display
xxx$xcodebuild -sdk iphoneos -configuration Debug
....
....
[self updateAccountInfo];1
^
1 warning and 1 error generated.
Is it possible to make xcodebuild display all compile errors?
In the Xcode's Preference, in the General Tab, check the "Continue building after errors" option. asked here
What I need is to use xcodebuild do the same thing.
EDIT:
After thinking and researching these days, I think xcodebuild can't do this. It's different from xcode. When we use xcode to compile iOS project, xcode compile every .m by clang. So xcode has "Continue building after errors" feature
You need to set the Xcode preferences to do this (from Terminal.app):
$ defaults write com.apple.Xcode PBXBuildsContinueAfterErrors YES
for xCode 8:
$ defaults write com.apple.dt.Xcode IDEBuildingContinueBuildingAfterErrors 1
If you want to continue building after errors using the latest version of xcodebuild/xctool you will need to run them with -IDEBuildingContinueBuildingAfterErrors=YES.
Example:
xctool -project SampleProject.xcodeproj/ -scheme SampleProject -sdk iphonesimulator build -IDEBuildingContinueBuildingAfterErrors=YES
Looks like PBXBuildsContinueAfterErrors isn't supported anymore.
Also you can use defaults write com.apple.dt.Xcode to make this setting permanent. If you want to have a look how you current version of IDE is controlling that setting you can call defaults read com.apple.dt.Xcode and search for "errors" and "continue".

"You can’t open the application because it is not supported on this type of Mac." xcodebuild

When I try to build my xcode project using the following command:
xcodebuild -workspace "Converse.xcworkspace" -sch
eme "Converse" -configuration “Debug” -sdk iphonesimulator7.1 -arch i386 ONLY_
ACTIVE_ARCH=NO
It builds fine, but when I try to double click on the app it generates, it says: You can’t open the application because it is not supported on this type of Mac. Does anyone know why this is happening?
iOS apps need the simulator to run. You can just, as you said run them from Xcode. If you do not have the project then you need to deploy them like :
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/iPhone\ Simulator.app/Contents/MacOS/iPhone\ Simulator -SimulateApplication /Path/ToIso.app/AppName
Use Xcode, not xcodebuild, to run your app on the simulator.

Using jenkins to build mulitple versions of an IOS app with a single target

I have an ios app that will have two versions (using preprocessor directives to determine what code to use for which version). I would like to automatically build each version of the app using Jenkins. I would also like to use a single target in the xcode project if possible. Is the possible using a multiple-configuration project in Jenkins; and if so, I would I go about accomplishing this?
You need to change the XCode scheme in your build script.
For example, if you had two schemes on for testing, say staging and production, you would need to have to build scripts that look similar to this.
xcodebuild -configuration Debug -scheme "Test Staging" -sdk iphonesimulator5.1 -arch i386 build
xcodebuild -configuration Debug -scheme "Test Prod" -sdk iphonesimulator5.1 -arch i386 build
Your schemes can then be configured in XCode to match the preprocessor directives.

Resources