问题
Having an issue since updating to Xcode 4.5 when running my unit tests via command line. The following is the output i'm seeing when i try to run my tests
Unknown Device Type. Using UIUserInterfaceIdiomPad based on screen size
Terminating since there is no workspace.
/Applications/Xcode.app/Contents/Developer/Tools/RunPlatformUnitTests.include:334: note: Passed tests for architecture 'i386' (GC OFF)
/Applications/Xcode.app/Contents/Developer/Tools/RunPlatformUnitTests.include:345: note: Completed tests for architectures 'i386'
Even though it does say the tests have passed and completed, I don't think they have actually have been run.
I'm using the following command to run the tests:
xcodebuild -workspace MyApp.xcworkspace -scheme MyAppTests -sdk iphonesimulator -configuration Debug clean build TEST_AFTER_BUILD=YES
Has anyone run into the same problem and can offer a solution?
回答1:
Just thought I should also share what I did for a solution to this issue. I followed the solution outlined in https://stackoverflow.com/a/10823483/666943 but converted the ruby script to shell. At the end I basically installed ios-sim
via homebrew and replace the Run Script
in the Build Phases
of my Test target with the following:
if [ "$RUN_UNIT_TEST_WITH_IOS_SIM" = "YES" ]; then
test_bundle_path="$BUILT_PRODUCTS_DIR/$PRODUCT_NAME.$WRAPPER_EXTENSION"
ios-sim launch "$(dirname "$TEST_HOST")" --setenv DYLD_INSERT_LIBRARIES=/../../Library/PrivateFrameworks/IDEBundleInjection.framework/IDEBundleInjection --setenv XCInjectBundle="$test_bundle_path" --setenv XCInjectBundleInto="$TEST_HOST" --args -SenTest All "$test_bundle_path"
echo "Finished running tests with ios-sim"
else
"${SYSTEM_DEVELOPER_DIR}/Tools/RunUnitTests"
fi
To start the test now I pass in the argument RUN_UNIT_TEST_WITH_IOS_SIM=YES
e.g.
xcodebuild -workspace MyApp.xcworkspace -scheme MyAppTests -sdk iphonesimulator -configuration Debug clean build RUN_UNIT_TEST_WITH_IOS_SIM=YES
回答2:
I noticed this issue in the beta versions of Xcode 4.5 / iOS 6. I've been working on a standalone unit tests runner to work around this problem. It works by compiling your unit test bundle, then compiling a version of your app that automatically runs the unit tests in a simulator environment.
The tool is by no means complete, but enough people seem to be having this issue that I'm releasing the tool as is for now. Please fork or comment so I can improve the tool.
xcodetest: https://github.com/sgleadow/xcodetest
Also keep an eye on this radar on the issue http://openradar.appspot.com/12306879
回答3:
xcodebuild -project ${PROJECT_PATH}/${PROJECT_NAME}.xcodeproj \
-scheme ${TEST_SCHEME} \
-configuration Debug \
-sdk iphonesimulator5.1 \
clean build \
TEST_AFTER_BUILD=YES
Setting the iphonesimulator to version 5.1 seems to solve the problem. There are radar bugs filled upon this issue.
This article also mention a good solution to follow:
http://baolei.tumblr.com/post/32428168156/ios-unit-test-from-command-line-ios6-xcode4-5
回答4:
Also there's little hack that can help to run command-line tests on iOS6.0 simulator SDK
I'm Using Cedar and this tweak helped me :
First, you need to update your main file a little:
// Faking up that workspace port
CFMessagePortCreateLocal(NULL, (CFStringRef) @"PurpleWorkspacePort", NULL, NULL,NULL);
return UIApplicationMain(argc, argv, nil, @"CedarApplicationDelegate");
Second, you need to add category to UIWindow:
@implementation UIWindow (Private)
- (void)_createContext {
// Doing nothing here. Just for crash avoidance
}
@end
Cedar Unittest will run fine, with some runtime warnings, but, at least they'll be able to run :)
来源:https://stackoverflow.com/questions/12557935/xcode-4-5-command-line-unit-testing