DZone
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
Refcards Trend Reports
Events Video Library
Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
View Events Video Library
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Integrating PostgreSQL Databases with ANF: Join this workshop to learn how to create a PostgreSQL server using Instaclustr’s managed service

Mobile Database Essentials: Assess data needs, storage requirements, and more when leveraging databases for cloud and edge applications.

Monitoring and Observability for LLMs: Datadog and Google Cloud discuss how to achieve optimal AI model performance.

Automated Testing: The latest on architecture, TDD, and the benefits of AI and low-code tools.

Related

  • Is It Okay To Stop Running Your Tests After the First Failure?
  • Testcontainers With Kotlin and Spring Data R2DBC
  • CI/CD Implementation: 5 Common Mistakes and How to Avoid Them
  • How to Test Gradle Plugins

Trending

  • Log Analysis: How to Digest 15 Billion Logs Per Day and Keep Big Queries Within 1 Second
  • Using Open Source for Data Integration and Automated Synchronizations
  • Beyond the Prompt: Unmasking Prompt Injections in Large Language Models
  • What Is GitOps?
  1. DZone
  2. Coding
  3. Java
  4. 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 · Tutorial
Like (4)
Save
Tweet
Share
6.10K 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.

Related

  • Is It Okay To Stop Running Your Tests After the First Failure?
  • Testcontainers With Kotlin and Spring Data R2DBC
  • CI/CD Implementation: 5 Common Mistakes and How to Avoid Them
  • How to Test Gradle Plugins

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

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

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: