Skip to content

Yet another programming solutions log

Sample bits from programming for the future generations.

Technologies Technologies
  • Algorithms and Data Structures
  • Java Tutorials
  • JUnit Tutorial
  • MongoDB Tutorial
  • Quartz Scheduler Tutorial
  • Spock Framework Tutorial
  • Spring Framework
  • Bash Tutorial
  • Clojure Tutorial
  • Design Patterns
  • Developer’s Tools
  • Productivity
  • About
Expand Search Form

Documenting Spock Framework Tests

farenda 2015-12-07 0

Problem:

Main feature of tests is their readability. How to use Spock Framework documenting features to increase readability of test reports.

Solution:

Probably not many people know, but there is a lot of features that make documenting Spock Framework tests a breeze:

  • @Title: for short, one-line descriptions of specifications.
  • @Narrative: for longer, more verbose descriptions. They usually have a form of User Stories “As…, I want…, to…“.
  • @Subject: clearly indicates what is being tested.
  • @See: a link to one or more references to external resources.
  • @Issue: a link to an issue.
  • Comments along Spock’s labels (expect, and, then, etc.).

Either @Narrative or @Title should be used, not both at once. It depends for whom you write the description and who is going to read test reports.

In the following example we’re going to show the annotations in action:

package com.farenda.spock

import spock.lang.Issue
import spock.lang.Narrative
import spock.lang.See
import spock.lang.Specification
import spock.lang.Subject
import spock.lang.Title

@Title('This test will test documenting features of Spock Framework')
@Narrative('''
As a Developer using Spock Framework for testing,
I want to be see Specifications documented,
so that my Business Analyst understand what is this all about.
''')
class DocumentingSpecTest extends Specification {

    // Clearly indicates System Under Test:
    @Subject controller = new UserController()

    @See('https://farenda.com/spock-framework-tutorial')
    def 'should have controller'() {
        expect:
        controller != null

        and: 'comments can be put here'
        controller.userService == null
    }

    @Issue('https://issues.farenda.com/PROJ-42')
    def 'should fix known math issue'() {
        expect:
        2 + 2 == 4
    }
}

By themselves the documenting annotations have no meaning to Spock Framework, but they are for consumption by external tools that generate test reports. For Spock there is Spock Reports library, which generates the report as you can see below:

Spock test reports
Spock test reports

Now you should know to document Spock Framework tests/specifications. ;-)

Share with the World!
Categories Spock Framework Tags unit-tests
Previous: Flexibly ignore tests in Spock
Next: AutoCleanup Spock test resources

Recent Posts

  • Java 8 Date Time concepts
  • Maven dependency to local JAR
  • Caesar cipher in Java
  • Java casting trick
  • Java 8 flatMap practical example
  • Linked List – remove element
  • Linked List – insert element at position
  • Linked List add element at the end
  • Create Java Streams
  • Floyd Cycle detection in Java

Pages

  • About Farenda
  • Algorithms and Data Structures
  • Bash Tutorial
  • Bean Validation Tutorial
  • Clojure Tutorial
  • Design Patterns
  • Java 8 Streams and Lambda Expressions Tutorial
  • Java Basics Tutorial
  • Java Collections Tutorial
  • Java Concurrency Tutorial
  • Java IO Tutorial
  • Java Tutorials
  • Java Util Tutorial
  • Java XML Tutorial
  • JUnit Tutorial
  • MongoDB Tutorial
  • Quartz Scheduler Tutorial
  • Software Developer’s Tools
  • Spock Framework Tutorial
  • Spring Framework

Tags

algorithms bash bean-validation books clojure design-patterns embedmongo exercises git gof gradle groovy hateoas hsqldb i18n java java-basics java-collections java-concurrency java-io java-lang java-time java-util java-xml java8 java8-files junit linux lists log4j logging maven mongodb performance quartz refactoring regex rest slf4j solid spring spring-boot spring-core sql unit-tests

Yet another programming solutions log © 2021

sponsored