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

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

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

谢谢

最佳答案

是的,我让它工作了。我的解决方案有些粗糙,可能并不适合所有情况。

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/

相关文章:

c++ - 这个 RAII 风格的 Objective-C 类可以工作吗?

iphone - 排行榜 "No Items"

ios - 访问另一个 Controller 中的数组

ios - 当我尝试在设备上部署 PhoneGAP 应用程序时,xCode 返回 'timed out waiting for app to launch' 错误

ios - iOS 版 UE4 AR(Kit) 开发中出现图标错误

objective-c - 如何将 NSTableView 绑定(bind)到自定义集合类?

ruby-on-rails - 具有存储库模式的 Ruby on Rails?

objective-c - isKindOfClass 没有按预期工作

java - 使用谓词作为单元测试的参数

java - 测试包装类