DZone
Java Zone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Java Zone > Spocklight: Indicate Specification as a Pending Feature

Spocklight: Indicate Specification as a Pending Feature

Working on a specification but don't want to implement it yet? @PendingFeature is a simple Spock annotation that will put your tests on the same page.

Hubert Klein Ikkink user avatar by
Hubert Klein Ikkink
·
Jun. 05, 17 · Java Zone · Tutorial
Like (4)
Save
Tweet
5.67K Views

Join the DZone community and get the full member experience.

Join For Free

Sometimes, we find ourselves working on a new feature in our code and we want to write a specification for it without yet really implementing the feature. To indicate we know the specification will fail while we are implementing the feature, we can add the @PendingFeature annotation to our specification method. With this annotation, Spock will still execute the test, but it will set the status to ignored if the test fails. But if the test passes, the status is set to failed. So when we have finished the feature, we need to remove the annotation — and Spock will kindly remind us to do so this way.

In the following example specification, we use the @PendingFeature annotation:

package sample

import spock.lang.Specification
import spock.lang.PendingFeature
import spock.lang.Subject

class SampleSpec extends Specification {

    @Subject
    private final converter = new Converter()

    @PendingFeature
    void 'new feature to make String upper case'() {
        given:
        def value = 'Spock is awesome'

        expect: // This will fail as expected
        converter.upper(value) == 'SPOCK IS AWESOME'
    }

}

class Converter {
    String upper(String value) {
        value
    }
}


When we run our test in, for example, Gradle we get the following result:

Image title

Now let's implement the upper method:

package sample

import spock.lang.Specification
import spock.lang.PendingFeature
import spock.lang.Subject

class SampleSpec extends Specification {

    @Subject
    private final converter = new Converter()

    @PendingFeature
    void 'new feature to make String upper case'() {
        given:
        def value = 'Spock is awesome'

        expect: // This will fail no more
        converter.upper(value) == 'SPOCK IS AWESOME'
    }

}

class Converter {
    String upper(String value) {
        value.toUpperCase()
    }
}


We run the test again and now we get a failing result although our implementation of the upper method is correct:

Image title

So this tells us the @PendingFeature is no longer needed. We can remove it and the specification will pass correctly.

Written with Spock 1.1.

Testing Annotation Spock (testing framework) Pass (software) Gradle Implementation

Published at DZone with permission of Hubert Klein Ikkink, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Why to Implement GitOps into Your Kubernetes CI/CD Pipelines
  • What Is Lean Software Development
  • Real-Time Supply Chain With Apache Kafka in the Food and Retail Industry
  • A First Look at CSS When and Else Statements

Comments

Java Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo