在终端中使用模拟器进行OCUnit应用程序测试

Mat*_*art 11 xcode unit-testing objective-c ocunit ios-simulator

是否可以使用终端命令启动在模拟器中运行的应用程序测试?

谢谢

ton*_*lon 14

是的,我得到了它的工作.我的解决方案有些粗糙,可能并不适用于所有情况.

免责声明:此解决方案需要编辑系统文件.它适用于我,但可能搞乱XCode的单元测试堆栈,特别是如果你不明白你在做什么.

/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
Run Code Online (Sandbox Code Playgroud)

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
Run Code Online (Sandbox Code Playgroud)

您可以将固定用户主页移动到其他位置,但我认为您需要移动.app和.octest包.

添加-RegisterForSystemEventsOTHER_TEST_FLAGS测试包的构建设置.

确保您的测试包包含包含内容的运行脚本构建阶段

# Run the unit tests in this test bundle.
"${SYSTEM_DEVELOPER_DIR}/Tools/RunUnitTests"
Run Code Online (Sandbox Code Playgroud)

为您的测试创建一个新方案.

您应该能够使用标准xcodebuild从命令行运行测试:

xcodebuild -workspace $(WORKSPACE_NAME).xcworkspace -scheme $(TEST_SCHEME) -configuration debug -sdk iphonesimulator

在运行测试时,模拟器不能运行.

我希望这些信息是完整的,如果某些内容无法按预期工作,请询问.