Highlighting Spock test keywords in Eclipse


I am using Eclipse for a Java project with some tests written in Groovy / Spock which uses the given: when: then: syntax. I would like these keywords to highlighted with some colour. Note: the spock plugin is supposed to this but doesn’t work. So wanted to just do this myself.


given:, when:, etc. are statement labels. There is currently no support for highlighting statement labels in Groovy-Eclipse. They are actually a bit tricky to pin down since they are not saved in the AST with source position information. org.codehaus.groovy.ast.stmt.Statement.getStatementLabels() returns List<String>. So it is possible to tell which statements have labels, but then the source range of the statement would need to be scanned to find the range of the label.

Answered By – emilles

Answer Checked By – Terry (AngularFixing Volunteer)

Leave a Reply

Your email address will not be published.