gpt4 book ai didi

ios - 由于 otest 错误,无法从命令行运行 Xcode 单元测试

转载 作者:行者123 更新时间:2023-12-01 17:26:17 25 4
gpt4 key购买 nike

我正在尝试从命令行运行单元测试,但它们在 Xcode 4.6 中运行得非常好时失败了。我无法弄清楚失败的原因是什么:

这是我正在使用的命令:

xcodebuild -sdk iphonesimulator -project myproject.xcodeproj 
-scheme 'MyProjectApplicationTests'
-configuration Debug clean build
RUN_UNIT_TEST_WITH_IOS_SIM=YES TEST_AFTER_BUILD=YES TEST_HOST=''

在我的测试中,我没有使用 NSURL 或“initFileURLWithPath”。这是错误:
/Applications/Xcode.app/Contents/Developer/Tools/RunPlatformUnitTests.include:412: note: Started tests for architectures 'i386'
Run unit tests for architecture 'i386' (GC OFF)
/Applications/Xcode.app/Contents/Developer/Tools/RunPlatformUnitTests.include:419: note: Running tests for architecture 'i386' (GC OFF)
2013-06-04 22:09:57.605 otest[85321:707] Unknown Device Type. Using UIUserInterfaceIdiomPhone based on screen size
2013-06-04 22:09:57.624 otest[85321:707] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSURL initFileURLWithPath:]: nil string parameter'
*** First throw call stack:
(0xa05012 0x71ce7e 0xa04deb 0x2a9b1 0x2a93b 0x4d3c5c9 0x71d7cf 0x724a0d 0x71baeb 0x71be22 0x72e0e1 0x2010879a 0x20106ef5 0x20107124 0x20107196 0x2010624c 0x201063da 0x7305c8 0x2342 0x25ef 0x268c 0x2001 0x1f71)
libc++abi.dylib: terminate called throwing an exception
/Applications/Xcode.app/Contents/Developer/Tools/RunPlatformUnitTests.include: line 415: 85321 Abort trap: 6 "${THIN_TEST_RIG}" "${OTHER_TEST_FLAGS}" "${TEST_BUNDLE_PATH}"
/Applications/Xcode.app/Contents/Developer/Tools/RunPlatformUnitTests.include:451: error: Test rig '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.1.sdk/Developer/usr/bin/otest' exited abnormally with code 134 (it may have crashed).

如果有办法甚至打印出调用堆栈(英文),我也许可以找出错误来自哪里。

最佳答案

问题是 xcodebuild 本身不支持模拟器中的应用程序测试。要从命令行在模拟器中运行应用程序测试,您需要一个开源实用程序 ios-sim 和一个用于测试目标运行脚本的 tweek。

1) 安装ios-sim https://github.com/phonegap/ios-sim

$ curl -L https://github.com/phonegap/ios-sim/zipball/1.9.0 -o ios-sim-1.9.0.zip
$ unzip ios-sim-1.9.0.zip
$ cd phonegap-ios-sim-538ef1a/
$ sudo rake install prefix=/usr/local/

2) 编辑您的测试目标运行脚本。该脚本来自 Atlassian 的精彩文档。我喜欢 JIRA、Stash、Confluence 的 Atlassian 制造商,以及我最好的新 friend SourceTree。完全披露他们收购了 SourceTree,它的开发者随后免费发布了它。

替换现有的:
# Run the unit tests in this test bundle.
"${SYSTEM_DEVELOPER_DIR}/Tools/RunUnitTests"

有了这个:(来源 https://confluence.atlassian.com/display/BAMBOO/Xcode)
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

enter image description here

3) 运行你的测试
xcodebuild \
-sdk iphonesimulator6.1 \
-project DC\ Wire\ Sizer.xcodeproj \
-target DC\ Wire\ Sizer\ Tests \
-configuration Debug \
RUN_UNIT_TEST_WITH_IOS_SIM=YES

...

Test Suite 'All tests' finished at 2013-06-06 16:03:35 +0000.
Executed 104 tests, with 0 failures (0 unexpected) in 0.991 (1.063) seconds

Finished running tests with ios-sim
Showing first 200 notices only


** BUILD SUCCEEDED **

有用的命令:

xcodebuild -showsdks
$ xcodebuild -showsdks
OS X SDKs:
Mac OS X 10.7 -sdk macosx10.7
OS X 10.8 -sdk macosx10.8

iOS SDKs:
iOS 6.1 -sdk iphoneos6.1

iOS Simulator SDKs:
Simulator - iOS 4.3 -sdk iphonesimulator4.3
Simulator - iOS 5.0 -sdk iphonesimulator5.0
Simulator - iOS 5.1 -sdk iphonesimulator5.1
Simulator - iOS 6.0 -sdk iphonesimulator6.0
Simulator - iOS 6.1 -sdk iphonesimulator6.1

xcodebuild -list -project
$ xcodebuild -list -project DC\ Wire\ Sizer.xcodeproj
Information about project "DC Wire Sizer":
Targets:
DC Wire Sizer
DC Wire Sizer Tests
In Work Unit Test

Build Configurations:
Debug
Release_AppStore
Release_TestFlight

If no build configuration is specified and -scheme is not passed then "Release_AppStore" is used.

Schemes:
DC Wire Sizer
DC Wire Sizer - App Store
InWorkUnitTest

应用程序测试与逻辑测试
为新项目创建的单元测试目标是应用程序单元测试。它通过在build设置中设置 BUNDLE_LOADER 和 TEST_HOST 将您的测试代码注入(inject)应用程序。
您从 New Target 菜单创建的测试目标是逻辑测试。逻辑测试独立于您的应用程序。

这是我的 Bundle Loader 和测试主机值。
Bundle Loader: $(BUILT_PRODUCTS_DIR)/DC Wire Sizer.app/DC Wire Sizer
Test Host: $(BUNDLE_LOADER)

潜在问题:如果您安装了多个版本的 Xcode。然后你需要检查你的 xcode-select 设置:
gdunham: ~$ xcode-select -print-path
/Applications/Xcode.app/Contents/Developer

关于ios - 由于 otest 错误,无法从命令行运行 Xcode 单元测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16932187/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com