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

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.

Related

xcodebuild gives signing error when it shouldn't

I execute the following xcodebuild command line:
xcodebuild CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO
-workspace "MyThing.xcworkspace" -scheme "MyScheme"
-configuration 'Debug' -sdk iphoneos clean build
and get this error:
error: An empty identity is not valid when signing a binary
for the product type 'Application'. (in target 'MyTarget')
This used to work. How can I fix it?
This is using Xcode 10.2.1.
For whatever reason, this seems to be (yet another) strange side effect of using Xcode's new build system. You can fix this from the xcodebuild command line by forcing use of the legacy build system, using the following flag:
-UseModernBuildSystem=0
To set up your project/workspace to use the legacy build system for everything, see here.
NOTE: While one can apparently still use it for a bit longer (in June 2022), the legacy build system is marked deprecated in Xcode 13.4.1)

xcodebuild fails, but building from Xcode succeeds

I'm trying to automate my build using xcodebuild.
However, my xcodebuild fails while building static libraries, complaining that it can't find headers that are part of dependency frameworks.
No problem to build from Xcode.
Why is the result of xcodebuild different from the one of Xcode?
You might accidentally build the Xcode project instead of the Xcode Workspace from xcodebuild.
If this is the case, replace:
xcodebuild -project "<*yourProjectFile*>.xcodeproj"
with:
xcodebuild -workspace <*yourWorkspaceFile*>.xcworkspace
After fixing this I get the exact same results from Xcode and xcodebuild.

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.

Running Xcode target from command line

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.

Resources