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

发布于 2024-11-18 11:55:33 字数 45 浏览 3 评论 0原文

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

谢谢

Is it possible to start an application test that runs in the simulator with a terminal command(s)?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

寄离 2024-11-25 11:55:33

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

免责声明:此解决方案需要编辑系统文件。它适用于
我,但可能会弄乱 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

模拟器不能是运行,当时你要运行什么测试。

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

Yes, I got it to work. My solution is somehow rough and might not be suitable in every case.

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.

In /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Tools/RunPlatformUnitTests
replace

if [ "${TEST_HOST}" != "" ]; then

    Warning ${LINENO} "Skipping tests; the iPhoneSimulator platform does not currently support application-hosted tests (TEST_HOST set)."

else

with

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

You may move the fixed user home to a different location, but I think you would need to move the .app and .octest bundles along.

Add -RegisterForSystemEvents to the OTHER_TEST_FLAGS build setting of your test bundle.

Make sure your test bundle contains a run script build phase with the contents

# Run the unit tests in this test bundle.
"${SYSTEM_DEVELOPER_DIR}/Tools/RunUnitTests"

Create a new scheme for your tests.

You should be able to run the tests from the command line using the standard xcodebuild:

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

The simulator must not be running, at the time you what to run the tests.

I hope this information is complete, if something doesn't work as expected please ask.

凡尘雨 2024-11-25 11:55:33

您可以使用以下命令确保模拟器未运行:

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

您可以使用以下命令确定模拟器是否处于活动状态:

sh -c 'ps -xaco 命令 | grep“iPhone模拟器”'

You can ensure that the Simulator isn't running with this:

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

You can determine if the Simulator is active with this:

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

沙与沫 2024-11-25 11:55:33

工作完美,谢谢!
自动化测试在我们的 Jenkins CI 服务器上恢复运行!
只需修复我的 TEST_HOST=${BUNDLE_LOADER}。如果运行测试时出现“没有此类文件”的错误,请执行此操作。

Worked perfectly, thanks!
Automated testing is back in action on our Jenkins CI-server!
Just had to fix my TEST_HOST=${BUNDLE_LOADER}. Do this if you get errors about "no such file" when running the tests.

黑寡妇 2024-11-25 11:55:33

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

It seems that with Xcode 4.5GM, running application tests in the simulator is now supported.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文