Spock, Grails

Spock-Reports for Grails 3.0

Spock-Reports is a great way to create better reports for Spock.

Since Grails 3.0 is based on Gradle, integrating the Spock-Reports is easy. Just open your build.gradle file and add

repositories {
  //for spock-reports

to the repositories section and

dependencies {
  //for spock-reports
  testCompile 'com.athaydes:spock-reports:1.2.5'  

to the dependencies section.

that’s it… The next time you run grails test-app, you’ll find the generated Spock-Reports in /build/spock-reports/

Customizing your Reports

If you want to customize your reports as described in the documentation, you have to create a file called META-INF/services/com.athaydes.spockframework.report.IReportCreator.properties. That sounds easier than it is, because it has to be in the classpath and for some Grails projects, it’s not easy to find the right folder to put it.

For Grails 3.0, you will succeed by putting it in src/test/resources/META-INF/services/com.athaydes.spockframework.report.IReportCreator.properties.

Here is a sample file which uses the template based reports:

# Name of the implementation class of the report creator
# Currently supported classes are:
#   1. com.athaydes.spockframework.report.internal.HtmlReportCreator
#   2. com.athaydes.spockframework.report.template.TemplateReportCreator

# Output directory (where the spock reports will be created) - relative to working directory

# If set to true, hides blocks which do not have any description

# Set properties of the report creator

this file specifies that the templates are located in src/test/resources/spockreporttemplates. A good idea is to start with the default templates spec-template.md and summary-template.md

You might want to use this https://github.com/rdmueller/Grails3.0-Spock-Reports-Sample as a starting point…

First appeared July 11, 2015 on rdmueller.github.io