Giter Club home page Giter Club logo

spock-mockable's Introduction

spock-mockable

spock mockable badge spock mockable stable spock mockable

spock-mockable allows creation of mocks otherwise un-mockable by the Spock Framework.

Spock is not capable of mocking private or final classes or methods because they are not accessible via inheritance. spock-mockable uses JVM instrumentation to modify these classes upon class loading and apply looser access restrictions. In consequence Spock then capable of mocking these classes.

  • Changes methode visibility private to protected

  • Removes final from classes and methods

  • Automatically attaches java agent

  • Redefines classes via Byte Buddy transformation.

  • Working with Spock Framework 1.3 and 2.0

Gradle Dependency

spock mockable?label=latest%20version

build.gradle
dependencies {
    testImplementation 'io.github.joke:spock-mockable:1.5.1'
}

Maven Dependency

pom.xml
<depenencies>
  <dependency>
    <groupId>io.github.joke</groupId>
    <artifactId>spock-mockable</artifactId>
    <version>1.5.1</version>
    <scope>test</scope>
  </dependency>
</depenencies>

Usage

Add the @Mockable annotation to your spock specification.

Make Person mockable
@Mockable(Person)
class PersonSpec extends Specification {
}
Make complete package io.github.joke mockable
@Mockable(packages = "io.github.joke")
class PersonSpec extends Specification {
}

More examples can be found in examples.

How does it work

All @Mockable annotations are scanned during groovy’s compilation phase for classes and registered. At the start of a test JVM these classes are transformed by the JVM instrumentation regardless of the actual test class the annotation has been placed on. This might lead to unexpected behaviour.

Conditionally disable transformation

You can disable spock-mockable by setting the JVM system property spock-mockable.disabled=true.

spock-mockable's People

Contributors

and1x0 avatar dependabot[bot] avatar fioan89 avatar github-actions[bot] avatar joke avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.