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

时间:2011-07-06 12:58:14

标签: objective-c xcode unit-testing ios-simulator ocunit

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

由于

4 个答案:

答案 0 :(得分: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

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版本设置中。

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

# 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

当您运行测试时,模拟器不能运行。

我希望这些信息是完整的,如果某些内容无法正常工作,请询问。

答案 1 :(得分:2)

您可以确保模拟器未运行:

osascript -e 'tell app "iPhone Simulator" to quit'

您可以通过以下方式确定模拟器是否处于活动状态:

sh -c 'ps -xaco command | grep "iPhone Simulator"'

答案 2 :(得分:1)

工作得很完美,谢谢! 我们的Jenkins CI服务器上的自动测试重新开始! 只需修复我的TEST_HOST=${BUNDLE_LOADER}。如果在运行测试时遇到“无此文件”错误,请执行此操作。

答案 3 :(得分:1)

似乎使用Xcode 4.5GM,现在支持在模拟器中运行应用程序测试。

相关问题