Running Xcode target from command line - xcode

I am new to running unit tests using Catch.
I am using the Catch to run unit tests in my Xcode project. I have added a target to my project which includes my Catch files and tests cases. Selecting that target and running from Xcode runs fine. I am now trying to get it to run from the command line which will be the way it is run from Jenkins. I have a shell script that contains:
xcodebuild clean install
xcodebuild -target TestApp -configuration “Debug” -sdk iphonesimulator7.1 CONFIGURATION_BUILD_DIR=TestBuild ONLY_ACTIVE_ARCH=NO
The result is:
** INSTALL SUCCEEDED **
Build settings from command line:
CONFIGURATION_BUILD_DIR = TestBuild
ONLY_ACTIVE_ARCH = NO
SDKROOT = iphonesimulator7.1
--- xcodebuild: WARNING: Configuration “Release” is not in the project. Building default configuration.
=== BUILD TARGET CreativeSDKTest OF PROJECT CreativeSDKImage WITH THE DEFAULT CONFIGURATION (Release) ===
Check dependencies
** BUILD SUCCEEDED **
But the application doesn’t launch in the simulator. Maybe I’m not seeing the obvious but from all the docs I’ve read, this should launch the application.

I think you'll need to tell xcodebuild to test the project:
xcodebuild clean install
xcodebuild -target TestApp -configuration “Debug” -sdk iphonesimulator7.1 CONFIGURATION_BUILD_DIR=TestBuild ONLY_ACTIVE_ARCH=NO clean test
(See the end of the last command)
EDIT: In fact you probably don't even need the first command and just the second will do.

Related

How to: `xcodebuild -xcworkspace..` with project and swift packages

I have created a xcworkspace to add my iOS.xcproj and local swift package. The workspace builds and runs great from Xcode. What would be the xcodebuild command to do in my CI?
I have been trying using the following:
xcodebuild -workspace [name].xcworkspace -scheme [scheme_name] -configuration [config] -xcconfig [path_xcconfig]
I get this in the output console:
...note: Building targets in dependency order
error: Multiple commands produce <RegisterExecutionPolicyException...
sample:
note: Target 'Firebase_FirebaseInAppMessaging_iOS' (project 'Firebase'): Touch /Users...

xcodebuild failed to build workspace with scheme. Reason - There is nothing to test

I have app with UITests target in Xcode 8.
I can run tests fine using Xcode. Now m trying to run them using command line.
xcodebuild test build-for-testing test-without-building -workspace
a.xcodeproj/project.xcworkspace -scheme testtargetscheme -destination
id=deviceuid -only-testing:StartupTestSuite
But it fails with: xcodebuild failed to build workspace with scheme. Reason - There is nothing to test.
I have checked scheme settings and made sure it does have tests enabled. I also tried above command with normal app run scheme, for which also I have test configured properly.
Any ideas?

Xcode 7: Xcode cannot run using the selected device

After upgrade to Xcode 7, Xcode cannot run tests on simulator.
$ xcodebuild test -sdk iphonesimulator -scheme MyProject
Build settings from command line:
SDKROOT = iphonesimulator9.0
xcodebuild: error: Failed to build project MyProject with scheme MyProject.
Reason: Xcode cannot run using the selected device.
The issue is reproduced on Travis CI and Jenkins. It's worked fine when I run xcodebuild test on a local machine.
I've gotten past this error by adding a flag like -destination 'name=iPhone 6'. It seems like xcodebuild used to pick a default destination but isn't doing that anymore. =|
I'm going to see if there is anything I can set in the build scheme to avoid hard coding a device.

Can't run Kiwi tests (XCTest) in xcodebuild (Xcode 6)

I'm trying to run my tests using the CLI tools. After following various guides, I came up with this command:
xcodebuild -workspace myworkspace.xcworkspace -scheme testsScheme -sdk iphonesimulator -arch i386 -configuration Debug TEST_AFTER_BUILD=YES clean build
The error I'm getting is:
The following build commands failed:
Ld /Users/<my name>/Library/Developer/Xcode/DerivedData/<project name>-gqrdtdiypfxjrbbjaqofxcjdckcg/Build/Products/Debug-iphonesimulator/<target or schema name>.xctest/<target or schema name> normal i386
I have no idea why the build fails as the error message is not very giving.
As for my pre-configuration, I've followed some guides and did the following: I've added a test-only scheme which targets my tests target (like I've seen in many guides), and also set it's executable to be the .app file (the default settings has no executable which results in an error that the app file is not found).
I'm using Cocoapods, and still not using the standard architecture (arm7, arm64) in my project (I'm dependent on a 3rd party that still hasn't upgraded, so currently my setting is $(ARCHS_STANDARD_32BIT)).
I've also checked that the "${SYSTEM_DEVELOPER_DIR}/Tools/RunUnitTests" run script appears and happens last in the build phases.
Note that running the tests using CMD+U works as intended.
EDIT: Apparently, The .app file wasn't created after a clean (so removing the clean or pre-building the app worked). Nevertheless (even though I need to solve this as well). I'm now getting this error:
PhaseScriptExecution Run\ Script /Users/shay/Library/Developer/Xcode/DerivedData/<name>-gqrdtdiypfxjrbbjaqofxcjdckcg/Build/Intermediates/<name>.build/Debug-iphonesimulator/<test schema>.build/Script-48FB07F617A93C57006E5E2A.sh
I've read that might happen when the iOS simulator is opened, but it happens even if I kill it before running the script.
After sleeping on it, I solved my issue by running:
xcodebuild -workspace <name>.xcworkspace -scheme <scheme> -sdk iphonesimulator -arch i386 -configuration Debug clean build test
Where the scheme is the original one, and not a specially-created one for the tests.

TeamCity Xcode Build Runner Configuration (Command Line)

I'm trying to setup a continuous build server with TeamCity and configure it so it can run "xcodebuild -configuration release -sdk iphoneos3.0 clean build".
i installed the plugin for teamcity-xcode integration and for the 'Build Runner' settings, i set it up as
Build Runner: Command Line
Command Executable: xcodebuild -configuration release -sdk iphoneos3.0 clean build
--The error -> [11:52:29]: RunBuildException when running build stage CallRunnerStage: Cannot run process xcodebuild -configuration "Release" : file not found
[11:52:30]: Build finished
But when i set the 'Command Executable' to just "xcodebuild", it works just fine but i need it to build the release config.
Thanks in advance for the help.
use the field command parameters for the parameters.

Resources