Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should domain objects and simple JavaBeans be unit tested?

Should simple JavaBeans that have only simple getters and setters be unit tested??

What about Beans with some logic in getters and setters?

like image 929
Behrang Avatar asked Sep 21 '08 16:09

Behrang


1 Answers

You should not write tests which:

  • Test the language or the IDE (i.e. automatically generated getters and setters)
  • Add no value to your test harness and kill your enthusiasm for Unit Testing

The same applies for .NET objects which only have properties (sometimes called 'Info' objects).

In an ideal world you would have 100% test coverage, but in practice this is not going to happen. So spend the client's money where it will add the most benefit i.e. writing tests for classes with complex state and behaviour.

If your JavaBean becomes more interesting you can of course add a test case later. One of the common problems associated with Unit Testing / TDD is the mistaken belief that everything has to be perfect first time.

like image 138
Garth Gilmour Avatar answered Oct 03 '22 07:10

Garth Gilmour