I like Spock Framework. I love it for its clarity, brevity and ease of adoption. So, I prepared a ‘lab’ style tutorial for Java programmers to convince them that it is beneficial to start using Spock.
Get started right away with the tutorial by cloning the github repo, or by downloading the zip and typing ‘./gradlew test’ in the homedir. Make sure to read the README.md file in the root directory before you start.
These are my top reasons to use Spock over jUnit + Mockito:
- A unit test is documentation, so readability matters. Spock tests make intuitive sense at first glance. This is a huge #win.
- Writing tests is an integral part of software development. If you can write them more quickly, you win lots of time. Spock’s DSL for testing allows precisely that.
Upon completing the tutorial (which should not take you much more than an hour or two) you (a Java programmer) will have learned:
- how a Spock test is structured
- that it feels very natural to write tests in that structure
- that it is not a problem to use Groovy to test code written in Java
- how easy it is do mock out collaborators of your component under test using Spock
- Don’t be fooled by the current version number. Spock is mature, I’ve used it for almost 2 years now!
Questions? please post them here and I will try to help you out.