Categories:
.NET (357)
C (330)
C++ (183)
CSS (84)
DBA (2)
General (7)
HTML (4)
Java (574)
JavaScript (106)
JSP (66)
Oracle (114)
Perl (46)
Perl (1)
PHP (1)
PL/SQL (1)
RSS (51)
Software QA (13)
SQL Server (1)
Windows (1)
XHTML (173)
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, 5751👍, 0💬
Popular Posts:
Can you explain in GSC and VAF in function points? In GSC (General System Characteristic) there are ...
How To Compare Two Strings with strcmp()? - PHP Script Tips - PHP Built-in Functions for Strings PHP...
How To Increment Dates by 1? - MySQL FAQs - Introduction to SQL Date and Time Handling If you have a...
What are different properties provided by Objectoriented systems ? Following are characteristic’s of...
What is hashing? To hash means to grind up, and that's essentially what hashing is all about. The he...