On 11/18/05, Jeff D. Chastain <[EMAIL PROTECTED]> wrote:
> So, I go to write a unit test around a simple bean object.  First test, 
> setName(name) ....
> Okay, obviously I need to pass in a string to this method, but as it is a 
> setter, it does not
> return anything.  So, what am I really testing here ... that the method does 
> not blow up,
> or how would I really test that it is doing what it is supposed to?  Do I 
> actually test the
> setName function by calling getName afterwards (in the same test function) 
> and then
> comparing the expected result?

Here is some food for thought too…
There is a common principle in the JUnit world: Don't test getters and
setters unless they do something special.
The reasoning is that in general they are too simple to break. Most
getter/setters are only doing a cfset and cfreturn. So if you were to
test them, you would really only be testing that you got the variable
name right.

One good resource is the Oracle white paper:
http://www.oracle.com/technology/products/jdev/collateral/papers/10g/GettingStartedWithUnitTesting.pdf
Which states this at the top of page 13. It also has a number of other
very good principles.

--
Rob Blackburn
http://www.rbdev.net

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Logware (www.logware.us): a new and convenient web-based time tracking 
application. Start tracking and documenting hours spent on a project or with a 
client with Logware today. Try it for free with a 15 day trial account.
http://www.houseoffusion.com/banners/view.cfm?bannerid=67

Message: http://www.houseoffusion.com/lists.cfm/link=i:4:224737
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

Reply via email to