If you want to unit test a private method, something may be wrong. Unit tests are (generally speaking) meant to test the interface of a class, meaning its public (and protected) methods. You can of course "hack" a solution to this (even if just by making the methods public), but you may also want to consider:

  1. If the method you'd like to test is really worth testing, it may be worth to move it into its own class.
  2. Add more tests to the public methods that call the private method, testing the private method's functionality. (As the commentators indicated, you should only do this if these private methods's functionality is really a part in with the public interface. If they actually perform functions that are hidden from the user (i.e. the unit test), this is probably bad).

http://stackoverflow.com/questions/250692/how-do-you-unit-test-private-methods

Do not to test a private method.的更多相关文章

  1. Private Variable and Private Method - Python 私有变量 和 私有方法

    Private Variable and Private Method Python 不象 Java 那样, 通过 private 关键字创建私有属性, python 通过更简洁的实现了'私有属性', ...

  2. thinking in java 读书笔记 --- overriding private method

    一个对象可以被用作它自身的类型或者是它的基类类型.当用作它的基类类型时叫做upcasting,如下所示 BaseClass ref = new DerivedClass()  //upcasting ...

  3. JAVA深入研究——Method的Invoke方法。

    在写代码的时候,发现Method可以调用子类的对象,但子类即使是改写了的Method,方法名一样,去调用父类的对象也会报错,虽然这是很符合多态的现象,也符合java的动态绑定规范,但还是想弄懂java ...

  4. JavaScript Patterns 5.3 Private Properties and Methods

    All object members are public in JavaScript. var myobj = { myprop : 1, getProp : function() { return ...

  5. 【PHP面向对象(OOP)编程入门教程】9.封装性(var与public,protected,private的关系)

    封装性是面象对象编程中的三大特性之一,封装性就是把对象的属性和服务结合成一个独立的相同单位,并尽可能隐蔽对象的内部细节,包含两个含义: 1. 把对象的全部属性和全部服务结合在一起,形成一个不可分割的独 ...

  6. 【PHP面向对象(OOP)编程入门教程】13.访问类型(public,protected,private)

    类型的访问修饰符允许开发人员对类成员的访问进行限制,这是PHP5的新特性,但却是OOP语言的一个好的特性.而且大多数OOP语言都已支持此特性.PHP5支持如下3种访问修饰符: public (公有的. ...

  7. php public protected private属性实例详解

    php 类中函数和类变量都有三个属性:public protected private,具体什么时候使用什么属性好纠结,特意找了个实例,这样看起来更清晰. public 表示全局,类内部外部子类都可以 ...

  8. .NET设计模式(16):模版方法(Template Method)(转)

    摘要:Template Method模式是比较简单的设计模式之一,但它却是代码复用的一项基本的技术,在类库中尤其重要. 主要内容 1.概述 2.Template Method解说 3..NET中的Te ...

  9. JAVA深入研究——Method的Invoke方法

    http://www.cnblogs.com/onlywujun/p/3519037.html 在写代码的时候,发现Method可以调用子类的对象,但子类即使是改写了的Method,方法名一样,去调用 ...

随机推荐

  1. 地铁沉降观测数据分析之巧用VBA编程处理

    地铁沉降观测数据分析之巧用VBA编程处理 当你观测了一天累的要死了,回来看着成百上千的测量数据,还要做报表.如果是三五页报表还好说,如果是2000个点的报表 按照一页纸张报30个点就得大约70页的报表 ...

  2. oracle中查询某张表都被哪些表参照了

    起因: 系统测试的时候发现如果某条记录已经被引用了,这个时候删除这条记录会引起数据不一致,系统会报错.比如警员信息,在考勤记录表里会引用警员ID,如果考勤记录表中已经存在这个警员ID了,这时从警员表中 ...

  3. timer.scheduleAtFixedRate和timer.schedule的实验

    基础代码: Calendar  currentTime = Calendar.getInstance(); currentTime.setTime(new Date()); int  currentH ...

  4. [原创]Android Handler使用Message的一个注意事项

    最近发现了一个莫名其妙的问题,在使用Handler.post(Runnable)这个接口时,Runnable有时候没有运行,非常奇怪,后来发现是因为调用Handler.removeMessage()时 ...

  5. 编写并发程序 Inversion

    做完了 scala parallel 课程作业后,觉得 scala 写并发程序的便捷性是 java 永远都追不上的.scala 的Future 和 Promise,java 里 Future 和 Co ...

  6. Multipart/form-data POST文件上传详解

    Multipart/form-data POST文件上传详解 理论 简单的HTTP POST 大家通过HTTP向服务器发送POST请求提交数据,都是通过form表单提交的,代码如下: <form ...

  7. 调用 google speech api (使用Google语音识别引擎)

    完全参考自: http://mikepultz.com/2011/03/accessing-google-speech-api-chrome-11/ http://aiku.me/bar/104480 ...

  8. SSAS:OLE DB 错误: OLE DB 或 ODBC 错误 : Login failed for user 'NT Service\MSSQLServerOLAPService'

    问题描述 按照微软官方教程尝试使用SSAS做OLAP时,出现如下错误信息: Severity Code Description Project File Line Suppression State ...

  9. C#连接mysql数据库插入数据后获取自增长主键ID值

    From: http://blog.csdn.net/zbc496218/article/details/51082983 MySqlConnection conn = new MySqlConnec ...

  10. log4j2配置

    在eclipse使用log4j2的时候遇到个问题: 我已经把log4j2.xml放到/src目录下了,而且设置从trace开始都打印到终端,但是我的程序里trace, info都不打印,到了error ...