是否可以使用终端命令启动在模拟器中运行的应用程序测试?
谢谢
最佳答案
是的,我让它工作了。我的解决方案有些粗糙,可能并不适合所有情况。
Disclaimer: This solution requires to edit system files. It works for me, but may mess up XCode's unit testing stack, especially if you do not understand what you are doing.
在 /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Tools/RunPlatformUnitTests
替换
if [ "${TEST_HOST}" != "" ]; then
Warning ${LINENO} "Skipping tests; the iPhoneSimulator platform does not currently support application-hosted tests (TEST_HOST set)."
else
与
if [ "${TEST_HOST}" != "" ]; then
mkdir -p "${BUILT_PRODUCTS_DIR}/Documents"
mkdir -p "${BUILT_PRODUCTS_DIR}/Library/Caches"
mkdir -p "${BUILT_PRODUCTS_DIR}/Library/Preferences"
mkdir -p "${BUILT_PRODUCTS_DIR}/tmp"
export CFFIXED_USER_HOME="${BUILT_PRODUCTS_DIR}/"
RunTestsForApplication "${TEST_HOST}" "${TEST_BUNDLE_PATH}"
else
您可以将固定用户主页移动到不同的位置,但我认为您需要将 .app 和 .octest 包一起移动。
将 -RegisterForSystemEvents
添加到测试包的 OTHER_TEST_FLAGS
build设置中。
确保您的测试包包含带有内容的运行脚本构建阶段
# Run the unit tests in this test bundle.
"${SYSTEM_DEVELOPER_DIR}/Tools/RunUnitTests"
为您的测试创建一个新方案。
您应该能够使用标准 xcodebuild 从命令行运行测试:
xcodebuild -workspace $(WORKSPACE_NAME).xcworkspace -scheme $(TEST_SCHEME) -configuration debug -sdk iphonesimulator
模拟器必须没有运行,在你运行测试的时候。
我希望这些信息是完整的,如果有什么不能按预期工作,请询问。
关于objective-c - 在终端中使用模拟器进行 OCUnit 应用程序测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6596741/