Should @Entity Pojos be tested

junit

I don't know if I should test my @Entity-annotated Pojos. After all, there are mainly just generated getters/setters. Should I test them?

When it comes to testing DAOs I'm using all those entities – so they are already propely tested, I guess?

Thanks for your thoughts.

Matt

Best Answer

Can your code contain any bugs? If not, what's the point in testing it? In fact, trying to test it would just introduce new bugs (because your tests could be wrong).

So the conclusion is: You should not test getters and setters without code (i.e. those which just assign or read a field without any additional code).

The exception is: When you manually write those getters/setters because you could have made a typo. But even then, some code will use these and there should be a test for that code which in turn tests whether the getters/setters behave correctly.

Related Topic