添加OCMock导致测试启动主应用程序,而不是运行测试 [英] Adding OCMock causes Test to launch main app instead of running tests

查看:336
本文介绍了添加OCMock导致测试启动主应用程序,而不是运行测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图添加OCMock到我现有的Cocoa项目,但我运行到一个奇怪的问题,我没有看到任何人覆盖。



我终于将它分离到以下:如果我简单地添加OCMock.framework引用到我的项目(即以某种方式拖动它到链接二进制与库构建阶段),当我运行测试,真正的应用程序被启动。



没有OCMock,输出是正常的:

 测试套件' 2013-02-07 20:07:03 +0000 

使用OCMock框架链接

 加载MyProjTests.octest / Contents / MacOS / MyProjTests时出错
未加载库:@ rpath / OCMock.framework /版本/ A / OCMock
原因:未找到图片
IDEBundleInjection.c:加载bundle'/ Users / alex / Library / Developer / Xcode / DerivedData / MyProj-bqwyxyspdiudktfnjcdgibdmpgsa / Build / Products / Debug / MyProjTests .octest'

此后,其他应用程序输出将正常显示。当应用程序运行时,测试进度在项目导航器的最后一个选项卡上旋转,并且不停止,直到你退出应用程序。



清除测试主机或软件包加载器并没有解决,只是为错误的架构产生了链接错误。 p>

我使用最新的Xcode,4.6。任何帮助非常感激。

解决方案

好吧,最后弄明白了,在我点击Submit之前, d分享答案。问题是OCMock.framework在运行时不可用。



官方OCMock步骤只是说下载并添加到目标,但不要告诉你添加复制阶段。我在测试目标中添加了一个新阶段,将框架复制到产品目录中,测试现在运行良好。



这是非常意外的,主应用程序将启动,



添加了图片。

每个人都喜欢图片



第1步

步骤2



第3步



步骤4


I'm trying to add OCMock to my existing Cocoa project, but am running to a strange problem that I don't see anyone else cover.

I finally isolated it to the following: if I simply add OCMock.framework reference to my project (i.e. drag it in somehow into Link Binary With Libraries build phase), when I run tests, the real app gets launched instead.

Without OCMock, the output is normal:

Test Suite 'Multiple Selected Tests' started at 2013-02-07 20:07:03 +0000

With OCMock framework link (partial output):

Error loading MyProjTests.octest/Contents/MacOS/MyProjTests
Library not loaded: @rpath/OCMock.framework/Versions/A/OCMock
Reason: image not found
IDEBundleInjection.c: Error loading bundle '/Users/alex/Library/Developer/Xcode/DerivedData/MyProj-bqwyxyspdiudktfnjcdgibdmpgsa/Build/Products/Debug/MyProjTests.octest'

Other app output then appears as normal after this point. While the app is running, test progress is spinning on last tab of project navigator, and doesn't stop until you Quit the app. So test is supposedly in progress the whole time your app is running.

Clearing test host or bundle loader didn't solve, only produced linking errors for wrong architecture.

I'm using latest Xcode, 4.6. Any help greatly appreciated.

解决方案

OK, finally figured it out, before I hit Submit here on SO, so I figured I'd share the answer. The problem was that OCMock.framework wasn't available at runtime.

The official OCMock steps just say download and add to target, but don't tell you to add a copy phase. I added a new phase in the test target to copy the framework into the Products Directory and the tests now run fine.

It was very unexpected that the main app would launch, and I hope this helps someone else.

edit:

Added pictures. Everyone loves pictures

Step 1

Step 2

Step 3

Step 4

这篇关于添加OCMock导致测试启动主应用程序,而不是运行测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆