Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should @Entity Pojos be tested?

Tags:

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

like image 290
Matt Avatar asked Dec 03 '08 14:12

Matt


People also ask

What is a POJO test?

POJO-TESTER is a java testing library, which makes your pojo-method tests much easier. You can test your pojo against equals , hashCode , toString , getters , setters and even constructors . POJO-TESTER automatically performs tests on basic pojo-methods so you don't have to copy-paste all dummy tests over and over.


2 Answers

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.

like image 70
Aaron Digulla Avatar answered Sep 29 '22 19:09

Aaron Digulla


The only reason I could think of the write tests would be to test the @Entity annotation itself. Testing the storage and retrieval of values seems like one is doubting a fundamental ability of our programming environment :)

like image 22
LenW Avatar answered Sep 29 '22 18:09

LenW