Categories:
.NET (961)
C (387)
C++ (185)
CSS (84)
DBA (8)
General (31)
HTML (48)
Java (641)
JavaScript (220)
JSP (109)
JUnit (31)
MySQL (297)
Networking (10)
Oracle (562)
Perl (48)
Perl (9)
PHP (259)
PL/SQL (140)
RSS (51)
Software QA (28)
SQL Server (5)
Struts (20)
Unix (2)
Windows (3)
XHTML (199)
XML (59)
Other Resources:
Under What Conditions Should You Not Test Get() and Set() Methods?
Under What Conditions Should You Not Test Get() and Set() Methods?
✍: FYICenter.com QA Team
The JUnit FAQ provides a good answer to this question:
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:
@Test public void testGetSetX() { setX(23); assertEquals(23, getX()); }
then you are testing the equivalent of the following:
@Test public void testGetSetX() { x = 23; assertEquals(23, x); }
or, if you prefer,
@Test public void 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:
@Test
public void testCreate() { assertEquals(23, new MyClass(23).getX()); }
2008-02-19, 5204👍, 0💬
Popular Posts:
Which bit wise operator is suitable for turning on a particular bit in a number? The bitwise OR oper...
How To Use SELECT Statement to Count the Number of Rows? - Oracle DBA FAQ - Understanding SQL SELECT...
How To Save Query Output to a Local File? - Oracle DBA FAQ - Introduction to Command-Line SQL*Plus C...
How To Increment Dates by 1? - Oracle DBA FAQ - Understanding SQL Basics If you have a date, and you...
What are shared (VB.NET)/Static(C#) variables? Static/Shared classes are used when a class provides ...