Blog

Running unit tests on iOS devices

09 Sep, 2014

When running a unit test target needing an entitlement (keychain access) it does not work out of the box on Xcode. You get some descriptive error in the console about a “missing entitlement”. Everything works fine on the Simulator though.
Often this is a case of the executable bundle’s code signature not begin valid anymore because a testing bundle was added/linked to the executable before deployment to the device. Easiest fix is to add a new “Run Script Build Phase” with the content:

codesign --verify --force --sign "$CODE_SIGN_IDENTITY" "$CODESIGNING_FOLDER_PATH"

codesign
Now try (cleaning and) running your unit tests again. Good chance it now works.

guest
4 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Joost
Joost
7 years ago

I think you mean “… undescriptive error …”

Chi Thu Le
Chi Thu Le
7 years ago

I still not understand how to run the unit test on a real device. Where the signing step above should be run ? Please help !
When I run this command:
xcodebuild test -project myapp.xcodeproj -scheme myapp-tests -sdk iphonesimulator
all tests run successfully on emulator.
I want to run the test on the real device and try this command:
xcodebuild test -project myapp.xcodeproj -scheme myapp-tests -sdk iphoneos
Build settings from command line:
SDKROOT = iphoneos8.1
xcodebuild: error: Failed to build project acc with scheme acc-tests.
Reason: Xcode cannot run using the selected device.

Chi Thu Le
Chi Thu Le
7 years ago

I got it work with following command line:
xcodebuild test -project myapp.xcodeproj -scheme myapp-tests -sdk iphoneos -destination name=’Chi Thu Le’s iPhone’
Thank you Jeroen for quick response.

Explore related posts