Wednesday, 14 October 2015

Spock Framework with spring , spring boot , hsql in memory db

To Start with disclaimer , I am new to Groovy so the syntax I used in this might not be the best practice but that shouldn't be problem as that is the not the problem statement.

Sample Project

The sample project is available on git.

Code is self explanatory . Basically I have tried to test a repository ( inserts data in in memory hsql db which is injected through Spring boot )  and stub a LDAP service which is normally called as part of authentication.

Version of frameworks used 

The best way to explain this section is to specify the pom I used

Integration with spring boot

It was smooth . The only hurdle was we can't use @SpringApplicationConfiguration  but need to use @ContextConfiguration directly as shown in the below code . This is the groovy  specification which is used for testing.

I have tried to cover

  • Simple Test case of null check
  • Data Driven Test (DDT)
  • And usage of mock 
A small hack which was needed to be done in case of DDT specially when using DataTables . It didn't allow for cases in which exceptions do occur . Its again self explanatory in the code.  


I personally found using spock with spring seamless . It was not only easy but due to its groovy influence it was much easier to write .

It incorporates the ease of mockito and brings in new features specially when it comes to mocking like the use of regular expression .

Loved the verbose nature of the failure scenarios which was pretty self explanatory.


At the end of my work I also found another really nice ebook :

No comments:

Post a Comment