This workshop is aimed to all those who want to learn and understand the basics of Spock Framework using Groovy.
If you want to follow this workshop by your own, we strongly recommend you to check Spock basics before start coding.
You can find three different exercises in /src/test/ in the master branch:
- Workshop01Spec.groovy: Basic testing handling exceptions and Data Driven Testing.
- Workshop02Spec.groovy: Usage of fixture methods.
- Workshop03Spec.groovy: Usage of Mocks and Stubs.
Each of the files is a Spock test, and you will find there some comments that explain what to do.
There already is working code in /src/main/ that you should not change. It works as it is, and you should only change the Spec files, creating everything you need in order to complete all the TODO tasks.
Each TODO task should be solved using only one feature method, but feel free to do it your way.
./gradlew test
First of all, import the project in IntelliJ:
- File > New > Project from Existing Sources...
- Select the build.gradle file.
- Select Use default gradle wrapper in the import process and an existing java version.
Finally, you can select a specific test file or a package and Secondary click > Run [file|Tests in package].
You will find our solutions proposal in the Solutions branch.
We tried to solve the tasks using different approaches in order to show different Spock features.
If you don't understand something in the solved exercises, we recommend you to search for it in the Spock Framework Reference Documentation. You will find there everything we used.