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.
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.
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
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.
Conclusion
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.
Reference
1) Spock Documentation : http://spockframework.github.io/spock/docs/1.0/
2) Spring Boot Documentation for Testing : http://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-testing.html
At the end of my work I also found another really nice ebook :
No comments:
Post a Comment