aspose file tools*
The moose likes Agile and Other Processes and the fly likes Clean Code A Handbook of Agile Software Craftsmanship - Test POJO Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Agile and Other Processes
Bookmark "Clean Code A Handbook of Agile Software Craftsmanship - Test POJO" Watch "Clean Code A Handbook of Agile Software Craftsmanship - Test POJO" New topic
Author

Clean Code A Handbook of Agile Software Craftsmanship - Test POJO

Tomasz Prus
Ranch Hand

Joined: May 20, 2008
Posts: 73
TDD question: How should i test domain classes when they have only getters and setters, what can i test? I heard that testing field accessors is nonsense.
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
You shouldn't.

In fact, quite likely you shouldn't have them: http://martinfowler.com/bliki/AnemicDomainModel.html


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Tomasz Prus
Ranch Hand

Joined: May 20, 2008
Posts: 73
So, if i have for example POJO Address? What should i do with it? What behavior i can add to this class?
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by Tomasz Prus:
So, if i have for example POJO Address? What should i do with it? What behavior i can add to this class?


Look out for the Feature Envy smell in the clients of the class: http://c2.com/cgi/wiki?FeatureEnvySmell
Robert Martin
Author
Ranch Hand

Joined: Jul 02, 2003
Posts: 76
Originally posted by Tomasz Prus:
TDD question: How should i test domain classes when they have only getters and setters, what can i test? I heard that testing field accessors is nonsense.


Don't test classes that have nothing but getters and setter. Don't HAVE classes that have just getters and setters. Such classes are not classes at all -- they are data structures and their variables should be public.

Yes, I know there are "bean" standards. (Sigh). OK, so if you have to conform to a silly standard like that, go ahead and make your getters and setters. But don't test them.

Oh, and read the "Data" chapter in "Clean Code".


---<br />Uncle Bob.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Clean Code A Handbook of Agile Software Craftsmanship - Test POJO