【发布时间】:2013-06-05 05:29:02
【问题描述】:
我正在尝试从命令行运行单元测试,但它们在 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).
如果有办法打印出调用堆栈(英文),我也许可以找出错误的来源。
【问题讨论】:
-
您正在尝试运行应用程序测试而不是逻辑测试,不是吗?你已经正确安装了
ios-sim? -
我有 iOS 模拟器应用程序,但当我在命令行输入“ios-sim”时,什么都没有。清单 /Applications/Xcode.app/Contents/Applications 显示我有“iPhone Simulator.app”。
-
关于应用程序测试与单元测试的区别,这是作为测试包创建的目标。我不确定是什么将测试区分为“逻辑测试”与“应用程序测试”——整个概念对我来说似乎很奇怪。尽管如此,测试都来自 SenTestCase。
-
正如@GayleDDS 所说,应用程序测试是作为应用程序的一部分执行的,这意味着 Xcode 将需要运行模拟器。逻辑测试只需要执行被 testet 的类。可以在
TEST_HOST构建配置变量中看到差异。如果它设置为您的应用程序可执行文件,则目标正在运行应用程序测试,如果它为空,它将运行逻辑测试。看看下面的帖子:Xcode 4: Run tests from the command line (xcodebuild)?。或者清除测试目标中的TEST_HOST变量。
标签: ios xcode unit-testing