测试内部类 [英] testing an internal class

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

问题描述

如何为内部类编写单元测试???

how to write unit tests to internal classes ???

推荐答案

您编写测试来指定顶级类的外部接口的行为.该类是否使用内部类来实现该行为,是该类的实现细节,测试不需要知道任何相关信息.

You write tests which specify the behaviour of the top-level class' external interface. Whether that class uses internal classes to implement that behaviour or not, is an implementation detail of the class, and the tests don't need to know anything about it.

如果内部类无法通过顶级类的接口进行充分测试,那么通常最好将内部类移出并直接将其作为新的顶级类进行测试.想要测试内部类是一种代码味道,内部类可能足够重要以成为顶级类.

If the internal class cannot be adequately tested through the top-level class' interface, then it's usually best to move the internal class out and test it directly as a new top-level class. Wanting to test internal classes is a code smell that the internal class might be significant enough to be a top-level class.

这篇关于测试内部类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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