Do not to test a private method.
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:
- If the method you'd like to test is really worth testing, it may be worth to move it into its own class.
- 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.的更多相关文章
- Private Variable and Private Method - Python 私有变量 和 私有方法
Private Variable and Private Method Python 不象 Java 那样, 通过 private 关键字创建私有属性, python 通过更简洁的实现了'私有属性', ...
- thinking in java 读书笔记 --- overriding private method
一个对象可以被用作它自身的类型或者是它的基类类型.当用作它的基类类型时叫做upcasting,如下所示 BaseClass ref = new DerivedClass() //upcasting ...
- JAVA深入研究——Method的Invoke方法。
在写代码的时候,发现Method可以调用子类的对象,但子类即使是改写了的Method,方法名一样,去调用父类的对象也会报错,虽然这是很符合多态的现象,也符合java的动态绑定规范,但还是想弄懂java ...
- JavaScript Patterns 5.3 Private Properties and Methods
All object members are public in JavaScript. var myobj = { myprop : 1, getProp : function() { return ...
- 【PHP面向对象(OOP)编程入门教程】9.封装性(var与public,protected,private的关系)
封装性是面象对象编程中的三大特性之一,封装性就是把对象的属性和服务结合成一个独立的相同单位,并尽可能隐蔽对象的内部细节,包含两个含义: 1. 把对象的全部属性和全部服务结合在一起,形成一个不可分割的独 ...
- 【PHP面向对象(OOP)编程入门教程】13.访问类型(public,protected,private)
类型的访问修饰符允许开发人员对类成员的访问进行限制,这是PHP5的新特性,但却是OOP语言的一个好的特性.而且大多数OOP语言都已支持此特性.PHP5支持如下3种访问修饰符: public (公有的. ...
- php public protected private属性实例详解
php 类中函数和类变量都有三个属性:public protected private,具体什么时候使用什么属性好纠结,特意找了个实例,这样看起来更清晰. public 表示全局,类内部外部子类都可以 ...
- .NET设计模式(16):模版方法(Template Method)(转)
摘要:Template Method模式是比较简单的设计模式之一,但它却是代码复用的一项基本的技术,在类库中尤其重要. 主要内容 1.概述 2.Template Method解说 3..NET中的Te ...
- JAVA深入研究——Method的Invoke方法
http://www.cnblogs.com/onlywujun/p/3519037.html 在写代码的时候,发现Method可以调用子类的对象,但子类即使是改写了的Method,方法名一样,去调用 ...
随机推荐
- H5长按事件
let timeOutEvent = 0 $(function () { $('#debug').on({ touchstart: function (e) { setTimeout(function ...
- No module named flask.ext.sqlalchemy.SQLALchemy
在学习<OReilly.Flask.Web.Development>的时候,按照书的例子到了数据库那一章,在运行python hello.py shell的时候出现了“ImportErro ...
- 一个winform带你玩转rabbitMQ
源码已放出 https://github.com/dubing/MaoyaRabbit 本章分3部分 一.安装部署初探 二.进阶 三.api相关 安装 部署 初探 先上图 一. 安装部署 下载 rab ...
- spring中@param和mybatis中@param使用差别
spring中@param /** * 查询指定用户和企业关联有没有配置角色 * @param businessId memberId * @return */ int selectRoleCount ...
- js后退一直停留在当前页面或者禁止后退
//禁用后退按钮 function stopHistoryGo() { //禁用回退 window.location.hash="no-back-button"; window.l ...
- 架设laravel
用laravel 架设的用户单点登录授权系统,git clone项目文件后,需要下面的方法初始化,纪录以供项目成员参考 错误信息:`Warning: require(/http/www.mywakav ...
- MT写的对URL操作的两个方法
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- shell编程总结
一.学习 shell脚本之前的基础知识 [linux shell中的特殊符号] 1. * :代表零个或多个字符或数字. test后面可以没有任何字符,也可以有多个字符,总之有或没有都能匹配出来. 2. ...
- WPF使用扩展屏幕
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- SAP的运输功能(转)
SAP的运输功能(transportation) transportation大体有三个作用: 1.运输计划transportation planning 概念:对outbound delivery ...