[Jhs-leads] JUnit testing
Kirkpatrick, Ivan
Ivan.Kirkpatrick@dep.state.fl.us
Fri, 15 Jul 2005 12:22:00 -0400
This is a multi-part message in MIME format.
------_=_NextPart_001_01C58959.53DD9678
Content-Type: multipart/alternative;
boundary="----_=_NextPart_002_01C58959.53DD9678"
------_=_NextPart_002_01C58959.53DD9678
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
I would like to point out that rather than write JUnit tests for simple
getters and setters in a class, it is acceptable to test the toString()
method of the class and compare the results to the expected value. A =
good
toString() method will output in String form the values of each field =
using
the getter method. This presumes the setter has already been exercised =
when
the class was instantiated or that an appropriate initialization of the =
class
was accomplished. Good JUnit tests are preferred rather than lots of =
JUnit
tests that are trivial.
=20
As with everything there are exceptions to the rule. If there is some =
other
reason for not testing the classes as required that reason should be
documented in the code. Ignoring the rules is not acceptable. =
Acknowledging
deficiencies in the code and providing explanations are much more =
palatable.
=20
I would like to add that Software Development Professionals general =
opinion
is that unit testing, code reviews and functional testing may require
additional resources and time upfront but that the payoff comes in =
reduced
debugging and troubleshooting efforts later on.
=20
I think it is also necessary to realize that these requirements provide =
the
best benefits when they are adopted early. By doing these things sooner =
and
continuously rather than at the end of a development cycle everyone can
obtain greater benefits. =20
=20
These requirements are not add ons. They are an integral part of =
software
development methodology.
Ivan S Kirkpatrick=20
=20
------_=_NextPart_002_01C58959.53DD9678
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; =
charset=3Diso-8859-1">
<TITLE id=3DridTitle>Clear Day</TITLE>
<STYLE>BODY {
MARGIN-TOP: 25px; FONT-SIZE: 10pt; MARGIN-LEFT: 10px; COLOR: #0033cc; =
FONT-FAMILY: Arial, Helvetica
}
</STYLE>
<META content=3D"MSHTML 6.00.2900.2627" name=3DGENERATOR></HEAD>
<BODY id=3DridBody background=3Dcid:850590016@15072005-1977>
<DIV><SPAN class=3D850590016-15072005>I would like to point out that =
rather than=20
write JUnit tests for simple getters and setters in a class, it is =
acceptable to=20
test the toString() method of the class and compare the results to the=20
expected value. A good toString() method will output in =
String form=20
the values of each field using the getter method. This presumes =
the setter=20
has already been exercised when the class was instantiated or that an=20
appropriate initialization of the class was accomplished. Good =
JUnit tests=20
are preferred rather than lots of JUnit tests that are =
trivial.</SPAN></DIV>
<DIV><SPAN class=3D850590016-15072005></SPAN> </DIV>
<DIV><SPAN class=3D850590016-15072005>As with everything there are =
exceptions to=20
the rule. I</SPAN><SPAN class=3D850590016-15072005>f there is some =
other=20
reason for not testing the classes as required that reason should be =
documented=20
in the code. Ignoring the rules is not acceptable. =
Acknowledging=20
deficiencies in the code and providing explanations are much more=20
palatable.</SPAN></DIV>
<DIV><SPAN class=3D850590016-15072005></SPAN> </DIV>
<DIV><SPAN class=3D850590016-15072005>I would like to add =
that Software=20
Development Professionals general opinion is that unit testing, =
code=20
reviews and functional testing may require additional resources and time =
upfront=20
but that the payoff comes in reduced debugging and troubleshooting =
efforts later=20
on.</SPAN></DIV>
<DIV><SPAN class=3D850590016-15072005></SPAN> </DIV>
<DIV><SPAN class=3D850590016-15072005>I think it is also necessary to =
realize that=20
these requirements provide the best benefits when they are adopted =
early. =20
By doing these things sooner and continuously rather than at the end of =
a=20
development cycle everyone can obtain greater benefits. =
</SPAN></DIV>
<DIV><SPAN class=3D850590016-15072005></SPAN> </DIV>
<DIV><SPAN class=3D850590016-15072005>These requirements are not add =
ons. =20
They are an integral part of software development =
methodology.</SPAN></DIV>
<P>Ivan S Kirkpatrick </P>
<P> </P></BODY></HTML>
------_=_NextPart_002_01C58959.53DD9678--
------_=_NextPart_001_01C58959.53DD9678
Content-Type: image/jpeg;
name="Clear Day Bkgrd.JPG"
Content-Transfer-Encoding: base64
Content-ID: <850590016@15072005-1977>
Content-Description: Clear Day Bkgrd.JPG
Content-Location: Clear%20Day%20Bkgrd.JPG
/9j/4AAQSkZJRgABAgEASABIAAD/7QVoUGhvdG9zaG9wIDMuMAA4QklNA+0AAAAAABAASAAAAAEA
AQBIAAAAAQABOEJJTQPzAAAAAAAIAAAAAAAAAAA4QklNBAoAAAAAAAEAADhCSU0nEAAAAAAACgAB
AAAAAAAAAAI4QklNA/UAAAAAAEgAL2ZmAAEAbGZmAAYAAAAAAAEAL2ZmAAEAoZmaAAYAAAAAAAEA
MgAAAAEAWgAAAAYAAAAAAAEANQAAAAEALQAAAAYAAAAAAAE4QklNA/gAAAAAAHAAAP//////////
//////////////////8D6AAAAAD/////////////////////////////A+gAAAAA////////////
/////////////////wPoAAAAAP////////////////////////////8D6AAAOEJJTQQIAAAAAAAQ
AAAAAQAAAkAAAAJAAAAAADhCSU0ECQAAAAAD9wAAAAEAAACAAAAAgAAAAYAAAMAAAAAD2wAYAAH/
2P/gABBKRklGAAECAQBIAEgAAP/+ACdGaWxlIHdyaXR0ZW4gYnkgQWRvYmUgUGhvdG9zaG9wqCA0
LjAA/+4ADkFkb2JlAGSAAAAAAf/bAIQADAgICAkIDAkJDBELCgsRFQ8MDA8VGBMTFRMTGBEMDAwM
DAwRDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAENCwsNDg0QDg4QFA4ODhQUDg4ODhQRDAwM
DAwREQwMDAwMDBEMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwM/8AAEQgAgACAAwEiAAIRAQMR
Af/dAAQACP/EAT8AAAEFAQEBAQEBAAAAAAAAAAMAAQIEBQYHCAkKCwEAAQUBAQEBAQEAAAAAAAAA
AQACAwQFBgcICQoLEAABBAEDAgQCBQcGCAUDDDMBAAIRAwQhEjEFQVFhEyJxgTIGFJGhsUIjJBVS
wWIzNHKC0UMHJZJT8OHxY3M1FqKygyZEk1RkRcKjdDYX0lXiZfKzhMPTdePzRieUpIW0lcTU5PSl
tcXV5fVWZnaGlqa2xtbm9jdHV2d3h5ent8fX5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