Thursday, March 1, 2012

Spring JpaRepository testing with @Configuration class, or only load the beans you need to test with

A lot of times its easier to load your entire production context when doing integration tests.  Obviously this can really slow down your test time as you're waiting for all the unnecessary beans to get loaded before the test runs.

Well not anymore!

I found a blog post about some pretty cool tools to use for testing.  Included in that was how to test using a @Configuration class.  Great start but what about our jpa:repository tags?  Well I wasn't the first person looking to replace jpa:repository tags with the java equivalent.

So from these two resources and with some playing around here is an example of how to use the @Configuration class to only load the repositories needed for testing.

No comments:

Post a Comment