Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to do unit test for my JPA class?

 
a shah
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to write unit tests for my JPA classes. Can anyone suggest me best way to do it? Is there any good framework for this? If you have some example please share it.

Thanks,
Atit
 
Aby Krishna
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From 'JPA Class', I understand you want to test Entity classes.

How is this going to be different from unit testing your other classes. A junit testcase to test persisting and retrieving your entity should be just fine.
 
E Armitage
Rancher
Posts: 989
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use an in memory database like Derby for your unit tests.
 
a shah
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the quick response.

I have integration test cases in which I am generating data using in memory database and test my functionality but Sonar don't consider them as coverage.
Thing is I have lots of different methods around my entities. I want to test all of them and make sure that Sonar also understand that I am covering all of my methods. So for this can you suggest some framework or some example?

Appreciate your help.

Thanks,
Atit
 
E Armitage
Rancher
Posts: 989
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1.) You can make sonar understand the integration tests results maybe via cobertura configs. This can be difficult to get right and will depend on versions of plugins you are using.
2.) You can move the JPA layer tests into unit tests. They depend on an in memory database so the should be fine to run as unit tests.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic