Win a copy of Rust Web Development this week in the Other Languages forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Spring DBUnit Testing

 
Ranch Hand
Posts: 608
Eclipse IDE Spring Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Guys,

I need some advice.. currently I am trying to implement DBUnit tests for our Spring application. I am using the the spring-test-dbunit module.
The problem that I have is that I do not want to start up the spring container to run unit-tests but it seems that I need to.

How can I test CrudRepository methods without a Spring container?

If this were a Java EE application I could construct an EntityManager and execute @NamedQueries to test my data access layer. But as this is Spring a lot of the data access methods that I need to test exist only on the CrudRepository interface!

How can I do this for a Spring application?
 
Marshal
Posts: 5218
323
IntelliJ IDE Python Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you can instantiate your database access classes as plain Java objects then you can just use regular dbunit and leave Spring out of it entirely.
 
Duran Harris
Ranch Hand
Posts: 608
Eclipse IDE Spring Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes that is what I am trying to do: Test as POJOs outside of the container.

It seems that what I need to investigate is how to instantiate a CrudRepository outside of Spring.
 
Tim Cooke
Marshal
Posts: 5218
323
IntelliJ IDE Python Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What does a CrudRepository look like?
 
Duran Harris
Ranch Hand
Posts: 608
Eclipse IDE Spring Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's an interface..


Although I just read an article here writing-tests-for-data-access-code-dont-test-the-framework that has kind of swayed me.

They recommend not writing unit tests for the data access layer when the logic contained in the JPQL is very simple and instead acheiving the same test-coverage with a few end-to-end tests.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic