单元测试Xcode中的私有方法 [英] Unit Testing of private methods in Xcode

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

问题描述

我正在玩一个玩具项目中的测试驱动开发。我可以得到的测试工作的公共接口我的类(虽然我仍然在围墙,因为我写的测试代码比测试的方法)。

I'm trying out test driven development in a toy project. I can get the tests working for the public interface to my classes (although I'm still on the fence because I'm writing more testing code than there is in the methods being tested).

我倾向于使用很多私有方法,因为我喜欢保持公共接口干净;

I tend to use a lot of private methods becuase I like to keep the public interfaces clean; however, I'd still like to use tests on these methods.

由于Cocoa是一个动态语言,我仍然可以调用这些私有方法,但是我在我的测试我的类可能不响应这些方法(虽然它明确)。因为我喜欢编译没有警告这里是我的问题:

Since Cocoa is a dynamic language, I can still call these private methods, but i get warnings in my tests that my class may not respond to these methods (although it clearly does). Since I like to compile with no warnings here are my questions:


  1. 如何在Xcode中关闭这些警告?
  2. $
  3. 在尝试白盒测试时我做错了什么?

  1. How do i turn off these warnings in Xcode?
  2. Is there something else I could do to turn off these warnings?
  3. Am I doing something wrong in trying 'white box' testing?


推荐答案


如何在Xcode中关闭这些警告?

How do i turn off these warnings in Xcode?

不要。


关闭这些警告?

Is there something else I could do to turn off these warnings?

不要。


我在尝试白盒测试时做错了什么?

Am I doing something wrong in trying 'white box' testing?

否。

解决方案是将您的私有方法移动到自己标题中的类别。将此标题导入真实类和测试用例类实现文件中。

The solution is to move your private methods to a category in its own header. Import this header into both the real class and test-case class implementation files.

这篇关于单元测试Xcode中的私有方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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