单元测试失败,然后不要 [英] Unit Tests fail, then don't

查看:126
本文介绍了单元测试失败,然后不要的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

经过一些严重的挫败和头痛之后,我设法将单元测试添加到现有项目中.问题是,测试只能在50%的时间执行.我有一个带有STFail宏的测试方法,当我运行测试时,它失败了,正如我所期望的那样.然后,我无需触摸任何代码/设置即可再次运行测试,并且测试将通过而不会碰到测试夹具中的断点.发生这种情况时,控制台将输出以下输出:

After some serious frustration and headaches, I've managed to add unit tests to an existing project. The problem is, the tests only get executed 50% of the time. I have a test method with an STFail macro inside, when I run the tests, it fails as I'd expect. Then, I run the tests again without touching any code/settings and it will pass without hitting breakpoints in the test fixture. The console prints out this output when this happens:

找不到位于... octest的测试包的可执行文件.

我有一个Google,但似乎没有多少人遇到这个确切的问题,关于这个问题的其他讨论也让我头疼.如果有人可以阐明这个问题,将不胜感激.

I've had a Google but there doesn't seem to be many/any people with this exact issue and other discussions on the subject are going over my head. If anyone can shed some light on this issue, It'll be very much appreciated.

谢谢.

推荐答案

我接受了您的新项目并重现了该问题.问题很多,一个未知:

I took your fresh project and reproduced the problem. There are a number of issues, and one unknown:

构建测试目标的阶段:

  • 目标依赖项:指定TestApp,以便始终首先构建主要目标.
  • 编译源:不包括任何主要源.仅包含TestAppUnitTests.mm
  • 将二进制文件与库链接:唯一需要的是SenTestingKit.framework.我们可以充分利用Foundation和UIKit.
  • 复制捆绑包资源:应该没有任何内容. (稍后,您可能需要特定于测试的资源.)

测试目标的构建设置:

  • 捆绑程序加载器应为$(BUILT_PRODUCTS_DIR)/TestApp.app/TestApp
  • 测试主机应为$(BUNDLE_LOADER)
  • Bundle Loader should be $(BUILT_PRODUCTS_DIR)/TestApp.app/TestApp
  • Test Host should be $(BUNDLE_LOADER)

主要目标方案:

  • 测试->信息应指定测试目标

但是,即使我进行了所有这些更改,您的项目仍然会有奇怪的行为.模拟器有时会获得一个名为$ {PRODUCT_NAME}的应用程序版本.即使调试应用程序,有时也会在Log Navigator中显示"Debug $ {EXECUTABLE_NAME}".所以还有其他问题,我不知道该怎么办.

But even if I make all these changes, your project still has the odd behavior. The simulator sometimes gets a version of the app named, literally, ${PRODUCT_NAME}. Even debugging the app sometimes shows "Debug ${EXECUTABLE_NAME}" in the Log Navigator. So something else is awry, and I don't know what.

最好的解决方案是从头开始创建一个新项目,并指定包含单元测试".我已经证明这行得通.

The best solution is to create a new project from scratch, specifying "Include Unit Tests". I've verified that this works.

这篇关于单元测试失败,然后不要的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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