Fastpoint
级别: 总版主
精华:
44
发帖: 5033
基地声望: 390 点
基地币: 1687 Bug
基地贡献: 0 点
好评度: 15 点
在线时间:818(小时)
注册时间:2005-10-08
最后登录:2008-07-22
|
[FAQ]要测试所有的get()、set()方法吗?
引用Kent Beck, Erich Gamma,连接地址:http://junit.sourceforge.net/doc/cookbook/cookbook.htm
Most of the time, get/set methods just can't break, and if they can't break, then why test them? While it is usually better to test more, there is a definite curve of diminishing returns on test effort versus "code coverage". Remember the maxim: "Test until fear turns to boredom."
Assume that the getX() method only does "return x;" and that the setX() method only does "this.x = x;". If you write this test:
testGetSetX() { setX(23); assertEquals(23, getX()); }
then you are testing the equivalent of the following:
testGetSetX() { x = 23; assertEquals(23, x); }
or, if you prefer,
testGetSetX() { assertEquals(23, 23); }
At this point, you are testing the Java compiler, or possibly the interpreter, and not your component or application. There is generally no need for you to do Java's testing for them.
If you are concerned about whether a property has already been set at the point you wish to call getX(), then you want to test the constructor, and not the getX() method. This kind of test is especially useful if you have multiple constructors:
testCreate() { assertEquals(23, new MyClass(23).getX()); }
[ 此贴被Fastpoint在2005-10-17 11:10重新编辑 ]
|
可不可不要这么样徘徊在目光内 你会察觉到我根本寂寞难耐 即使千多百个深夜曾在梦境内 我有吻过你这毕竟并没存在
人声车声开始消和逝 无声挣扎有个情感奴隶 是我多么的想她 但我偏偏只得无尽叹谓
其实每次见你我也着迷 无奈你我各有角色范围 就算在寂寞梦内超出好友关系 唯在暗里爱你暗里着迷 无谓要你惹上各种问题 共我道别吧别让空虚使我越轨
|
|
[楼 主]
|
Posted: 2005-10-14 19:54 |
| |