如何覆盖内部类的方法? [英] How to cover methods of inner classes?

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

问题描述

我在如何覆盖内部类的方法方面遇到了问题.我有一个带有几个按钮和内部类形式的已定义动作侦听器的小型GUI(摇摆)应用程序.现在,我想为这些内部类中定义的每个动作侦听器方法编写测试,但是当我使用Eclipse创建新的JUnit时,我没有选择覆盖内部类的方法,而是类的唯一公共方法这些内部定义的地方.请指教.

I'm faced with a problem on how to cover methods of my innner classes. I have a small GUI (swing) application with several buttons and defined action listeners in form of inner classes. Now I want to write tests for each of the action listener methods defined in these inner classes but when I'm creating a new JUnit using Eclipse I don't have a option to cover methods of inner classes but the only public methods of the Class where those inners are defined. Please advice.

推荐答案

从概念上讲,内部方法通常不使用单元测试进行测试,因为内部方法被认为是实现细节.您应该测试<通过测试类的公共方法来了解他们的行为.

Conceptually, inner methods are not generally tested with unit tests, because they are considered an implementation detail. You should be testing the behavior of your class by testing its public methods.

那是... http://www.artima.com/suiterunner/private.html

我不确定为什么您需要内部类...在其他任何地方都没有使用它们?为什么不让他们在您的主要班级之外公开授课呢?

I'm not sure why you need inner classes...They're not used anywhere else? Why not just make them public classes outside of your main class?

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

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