7

FitNesse has a wiki-style documentation feature. It provided both the code and the doc's for these specification tests.

Is there a way in Spock (with plugin? / out of the box?) to generate any type of similar documentation to show off to the project managers / stakeholders, who can not be expected to read the (Groovy) source code of the Spock specifications.

Raedwald
  • 46,613
  • 43
  • 151
  • 237
Lorin S.
  • 754
  • 8
  • 29

3 Answers3

11

Well, I have used the Strings that describe each Spock block in your tests to generate HTML reports. Please visit my project and let me know if that helps:

https://github.com/renatoathaydes/spock-reports

You can download the jar from the reports directory and then just add it to your classpath. Run your tests, and "miraculously" you will have reports generated in the directory build/spock-reports!

You can even provide your own CSS stylesheets if you want to customize the reports, as explained in README.

Here's a blogpost I wrote about writing this Spock extension.

UPDATE

spock-reports has been available on Maven Central for a while now, as well as JCenter.

Renato
  • 12,940
  • 3
  • 54
  • 85
  • 1
    UPDATE: you don't need to download the jar, spock-reports is available from JCenter as a maven artifact. – Renato Nov 26 '14 at 16:20
  • Hi There, I was wondering if there is a possibility to include console logs along with the spock reports. I am visualizing something like a expand button around when: then: tags and expanding these will display corresponding console logging if any. Also, I would like to contribute to this if it is possible to implement and moved to GIT. – Raghu Kiran May 05 '16 at 11:21
  • please use [Github](https://github.com/renatoathaydes/spock-reports) for feature requests. – Renato May 06 '16 at 20:58
3

Spock allows you to add descriptions to blocks, e.g.:

when: "5 dollars are withdrawn from the account"
account.withdraw(5)

then: "3 dollars remain"
account.balance == 3

While we don't use this information yet, it's easy to access from an extension (see link below). What's left to do is to turn this into a nice report.

https://github.com/spockframework/spock-uberconf-2011/blob/master/src/test/groovy/extension/custom/ReportExtension.groovy

Peter Niederwieser
  • 121,412
  • 21
  • 324
  • 259
  • I've been using the commenting feature and was wondering how that became a part of the output. Thanks Peter! – Lorin S. Aug 05 '11 at 13:24
  • Looks like NFJS took down the pps attachment that you had there. I'll do some googling on researching extensions & reports. Any add'l info you may be able to provide would be great. Thanks again. – Lorin S. Aug 05 '11 at 13:34
  • The GitHub repo I've linked to above contains all the material from my latest talk, including the slides. – Peter Niederwieser Aug 08 '11 at 05:54
0

There are some great answers in here already, but if you want to keep your BDD definitions free from any plumbing whatsoever, you can take a look at pease, which will let you use Gherkin specification language with Spock.

Michal M
  • 1,521
  • 14
  • 35
  • 2
    Unfortunately [pease is now unmaintained](http://pease.github.io/2015/10/06/unmaintained.html): _Pease is outdated and won't be further developed or maintained. My recommendation is to have a look at the cucumber-jvm project._ – ninj Nov 21 '18 at 22:28