• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to do unit test for my JPA class?

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 989
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Curse your sudden but inevitable betrayal! And this tiny ad too!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic