Reputation: 1283
I've been trying to figure out how to run our Unit Tests from the command line, so that we can automate them. I'm using XCode 4.5.2, and building an IOS application.
First I tried using this:
xcodebuild -target "Unit Tests" -configuration "Debug (test syncserver)" -sdk iphonesimulator6.0 clean build TEST_AFTER_BUILD=YES
That would run the compile, but the test didn't run. So, after reading other solutions around here, I installed ios-sim and setup my target to run this script afterward: (Note that I had to replace occurences of "TEST_HOST" with "CODESIGNING_FOLDER_PATH" as TEST_HOST doesn't seem to exist in my builds.)
#!/bin/bash
if [ "$RUN_UNIT_TEST_WITH_IOS_SIM" = "YES" ]; then
test_bundle_path="$BUILT_PRODUCTS_DIR/$PRODUCT_NAME.$WRAPPER_EXTENSION"
echo ios-sim launch "$(dirname "$CODESIGNING_FOLDER_PATH")" --setenv DYLD_INSERT_LIBRARIES=/../../Library/PrivateFrameworks/IDEBundleInjection.framework/IDEBundleInjection --setenv XCInjectBundle="$test_bundle_path" --setenv XCInjectBundleInto="$CODESIGNING_FOLDER_PATH" --args -SenTest All "$test_bundle_path"
ios-sim launch "$(dirname "$CODESIGNING_FOLDER_PATH")" --setenv DYLD_INSERT_LIBRARIES=/../../Library/PrivateFrameworks/IDEBundleInjection.framework/IDEBundleInjection --setenv XCInjectBundle="$test_bundle_path" --setenv XCInjectBundleInto="$CODESIGNING_FOLDER_PATH" --args -SenTest All "$test_bundle_path"
echo "Finished running tests with ios-sim"
else
"${SYSTEM_DEVELOPER_DIR}/Tools/RunUnitTests"
fi
Now, when I run the same xcodebuild command as before, I get this:
/bin/sh -c "\"/Users/johnlussmyer/tu/ondeck/OnDeck/build/OnDeck.build/Debug (test syncserver)-iphonesimulator/Unit Tests.build/Script-4CECE52812D5043F0063EC6A.sh\"" ios-sim launch /Users/johnlussmyer/tu/ondeck/OnDeck/build/Debug (test syncserver)-iphonesimulator --setenv DYLD_INSERT_LIBRARIES=/../../Library/PrivateFrameworks/IDEBundleInjection.framework/IDEBundleInjection --setenv XCInjectBundle=/Users/johnlussmyer/tu/ondeck/OnDeck/build/Debug (test syncserver)-iphonesimulator/UnitTests.app --setenv XCInjectBundleInto=/Users/johnlussmyer/tu/ondeck/OnDeck/build/Debug (test syncserver)-iphonesimulator/UnitTests.app --args -SenTest All /Users/johnlussmyer/tu/ondeck/OnDeck/build/Debug (test syncserver)-iphonesimulator/UnitTests.app [DEBUG] Session could not be started: Error Domain=DTiPhoneSimulatorErrorDomain Code=1 "Unknown error." UserInfo=0x7fcf04b03190 {NSLocalizedDescription=Unknown error., DTiPhoneSimulatorUnderlyingErrorCodeKey=-1} Finished running tests with ios-sim
Any suggestions on what to try next?
Upvotes: 2
Views: 1822
Reputation: 11646
A bit old question.. but I fall here some similar question.
My two cents for OSX/ iOS (tested under iOS13 / Catalina / Xcode 11). (hope it can help someone..)
func underXCTest()->Bool{
let environment = ProcessInfo.processInfo.environment
if let _ = environment["XCInjectBundleInto"]{
return true
}
return false
}
Under testing return false.
Upvotes: 0
Reputation: 31
From the log, it seems you have several wrong settings. The correct syntax is:
ios-sim launch YourApp.app
--setenv DYLD_INSERT_LIBRARIES=/../../Library/PrivateFrameworks/IDEBundleInjection.framework/IDEBundleInjection
--setenv XCInjectBundle=YourTest.octest
--setenv XCInjectBundleInto=YourApp.app/YourApp
--args -SenTest All YourTest.octest
You could see that
If you can't see TEST_HOST in your environment variables, you may want to go through them to find some propers ones to make your bash script correct.
Upvotes: 3