Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Clean Code A Handbook of Agile Software Craftsmanship - Test POJO

 
Tomasz Prus
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You shouldn't.

In fact, quite likely you shouldn't have them: http://martinfowler.com/bliki/AnemicDomainModel.html
 
Tomasz Prus
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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".
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic