spock | The Enterprise-ready testing and specification framework | Unit Testing library

 by   spockframework Java Version: spock-2.4-M1 License: Apache-2.0

kandi X-RAY | spock Summary

kandi X-RAY | spock Summary

spock is a Java library typically used in Testing, Unit Testing, Framework applications. spock has no bugs, it has no vulnerabilities, it has build file available, it has a Permissive License and it has high support. You can download it from GitHub.

Spock is a BDD-style developer testing and specification framework for Java and [Groovy] applications. To learn more about Spock, visit To run a sample spec in your browser, go to

            kandi-support Support

              spock has a highly active ecosystem.
              It has 3376 star(s) with 460 fork(s). There are 140 watchers for this library.
              There were 5 major release(s) in the last 12 months.
              There are 212 open issues and 712 have been closed. On average issues are closed in 276 days. There are 54 open pull requests and 0 closed requests.
              It has a positive sentiment in the developer community.
              The latest version of spock is spock-2.4-M1

            kandi-Quality Quality

              spock has 0 bugs and 0 code smells.

            kandi-Security Security

              spock has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
              spock code analysis shows 0 unresolved vulnerabilities.
              There are 0 security hotspots that need review.

            kandi-License License

              spock is licensed under the Apache-2.0 License. This license is Permissive.
              Permissive licenses have the least restrictions, and you can use them in most projects.

            kandi-Reuse Reuse

              spock releases are available to install and integrate.
              Build file is available. You can build the component from source.
              Installation instructions are not available. Examples and code snippets are available.
              spock saves you 12373 person hours of effort in developing the same functionality from scratch.
              It has 24512 lines of code, 3268 functions and 580 files.
              It has medium code complexity. Code complexity directly impacts maintainability of the code.

            Top functions reviewed by kandi - BETA

            kandi has reviewed spock and discovered the below as its top functions. This is intended to give you an instant insight into spock implemented functionality, and help decide if they suit your requirements.
            • Implements the visitor to try catch - catch exceptions
            • Creates a default value initializer
            • Takes the RHSExpression and converts it to a method call
            • Creates the handle statement for the throwable throwable
            • Render the given expression
            • Checks if this is an equality comparison
            • Returns true if this node is a set comparison
            • Create the mock object with the specified configuration
            • Set the meta - class for the given object
            • Renders the given object
            • Intercept the method invocation
            • Create a new run context
            • Flattens a repeating extension annotation container
            • Analyze the spec
            • Returns the execution mode of this node
            • Visit a closure expression
            • Intercept the specified method invocation
            • Evaluate the node info
            • Overrides the visitor to visit a binary expression
            • Convert a string to a constant camel case
            • Creates the renderer
            • Visit a spec
            • Returns a string representation of this class
            • Provide a description of a mismatch
            • Add an interaction to this mock
            • Verify method condition
            Get all kandi verified functions for this library.

            spock Key Features

            The Enterprise-ready testing and specification framework.

            spock Examples and Code Snippets

            No Code Snippets are available at this moment for spock.

            Community Discussions


            java.lang.RuntimeException: not supported: class org.spockframework.gentyref.CaptureTypeImpl
            Asked 2022-Mar-30 at 13:59

            Spock is being used to execute an integration test in a Spring Boot project (2.1.18.RELEASE). When I run with 1.3-groovy-2.5, I get this error:



            Answered 2022-Mar-28 at 21:40

            Regarding java.util.ServiceConfigurationError: org.junit.platform.engine.TestEngine: org.spockframework.runtime.SpockEngine Unable to get public no-arg constructor

            Spring Boot 2.1.18.RELEASE is really old, it manages JUnit 5 to 5.3.2 while Spock 2.x requires >= 5.8. You can try setting 5.8.1 if you can't upgrade Spring Boot to a more recent version.

            As for the type reflection error, we can't say much since you didn't share any code. Only that com.foo.controller.ConversionsController.createConversionJob(ConversionsController.java:68) probably has some weird generics or is calling something that does.

            Source https://stackoverflow.com/questions/71653646


            How do I get spock-reports to generate index.html instead of getting 'ClassCastException class [B cannot be cast to class [C'
            Asked 2022-Mar-23 at 06:43

            When generating unit test reports using spock-reports, I'm getting a ClassCastException:



            Answered 2022-Mar-23 at 06:43
            System Property

            Aside from updating the other dependencies to later versions and aligning groovy versions, which ought to resolve it, a quick fix is to declare a system property:

            Source https://stackoverflow.com/questions/71582041


            How to tell if Spock is actually executing tests in parallel
            Asked 2022-Mar-12 at 10:34

            We have some API integration tests that take ~30 minutes to run a test class with 19 rows in the where: table. We're trying to speed this up using Spock's (experimental) Parellel Execution feature. We are using a simple SpockConfig.groovy file:



            Answered 2022-Mar-12 at 10:34

            You can parallelise Spock testing on several levels, i.e. per specification (test class) or per feature (test method). The per-method setting also means that in iterated (unrolled) tests, iterations can run in parallel. Here is some proof:

            Source https://stackoverflow.com/questions/71386473


            Testing an SFTP client with Spock Framework
            Asked 2022-Feb-13 at 00:56

            We actually use JUnit and the great FakeSftpServerRule junit rule to test a custom SFTP client we made. That was working great.

            Lastly, we want to get rid of junit in favor of the spock framework because we try to migrate to groovy.

            Do you guys know any equivalent of FakeSftpServerRule or any way to "switch" a junit rule into a spock rule equivalent ?

            Thank you a lot.



            Answered 2022-Feb-13 at 00:56

            The same author also published Fake SFTP Server Lambda, which is independent of the test framework in contrast to the JUnit 4 rule you use.

            If you want to stick with the old tool, Spock 1.3 can also use JUnit 4 rules, and in Spock 2.x it might also work with the JUnit 4 compatibility layer.

            Update: Here is an example program using the SSHJ library for downloading a file from an SFTP server, so we have a subject under test:

            Source https://stackoverflow.com/questions/71081881


            "No qualifying bean" for repository in Groovy Spring JPA application
            Asked 2022-Jan-10 at 19:12

            I know there are a bunch of similar questions on this topic, however all of them that I've found so far are either not quite my situation, or refer to one of the following solutions that from what I've read is either outdated or inapplicable:

            • @EnableJpaRepositories annotation - taken care of by @SpringBootApplication
            • @Repository annotation - not needed when extending Repository interface

            The error:



            Answered 2022-Jan-05 at 01:12

            nasch Are you sharing actual code/error snippets Few observations

            1. Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.package.repository.ChannelBalanceAdjustmentRepository' how you can have a package name containing package.. its a reserverd keyword and will not be allowed.
            2. Your repository which is in a different package and without public keyword how its accessible in the service package.

            Source https://stackoverflow.com/questions/70586397


            MissingPropertyException in Spock test
            Asked 2021-Dec-30 at 22:50

            I have problem with test written in groovy (using Spock as a framework). While I try fetch property in then block and then use it in interaction I receive No such property: updatedValue for class: my.test.class.MyTestClass on the interaction with event publisher. Can anyone tell why is that?



            Answered 2021-Dec-30 at 22:50

            You are encountering a side-effect of Spock's magic.

            Your method basically gets transformed to this:

            Source https://stackoverflow.com/questions/70519796


            Data from test with @Transactional are persisting between tests
            Asked 2021-Dec-16 at 21:36

            I have a small problem. I have started writing tests for my small project. The project uses SpringBoot, standard JpaRepository from Spring, as a testing framework I am using Spock and for testing the database, I'm using PostgreSQL container from TestContainers. The problem is, that data between tests is being persisted, despite the @Transacional on each of the tests. The strangest part is, that in the logs I can see, that transaction is rolled back. I would appreciate any help.

            So, these are the files:

            1. File with a shared container for tests, that all integration tests should extend from:


            Answered 2021-Dec-16 at 21:36

            Your tests start an app that listens on a real port. And you use TestRestTemplate to make HTTP calls. It's the same as if you ran your test from a remote machine - would you expect @Transactional on such tests to be some how applied to the app?

            @Transactional will work only if you invoke your endpoint directly, without any network calls:

            • either inject endpoint object directly to your test and call its method
            • or use MockMvc (or RestAssured+MockMvc) - it will also eventually call the endpoint directly

            Both of these options will simplify debugging - you'll be able to see in call stack which test is calling your production code at the moment.

            PS: also it shouldn't be a problem when your data is kept between test runs. You can isolate your tests with randomization.

            Source https://stackoverflow.com/questions/70385698


            How to mock Grails request object method in Spock controller test
            Asked 2021-Dec-01 at 08:57

            I'm trying to write a test for one of my controller classes. In this controller, I call request.reader.text which can throw MalformedInputException if the body contains non-utf-8 characters.

            This is the case I'm trying to test and mock in my Spock test. The easiest would be if I could mock the getReader() method, but that turns out to be difficult.

            Things I've tried:

            Should work according to this post (but does not): How to mock HttpServletRequest in Spock



            Answered 2021-Dec-01 at 08:57

            I finally managed to find a solution after some more frantic googling. Although, this is not as clean as I would have wished, it works!

            The only way I've found it possible to manipulate the request and response objects in a controller is by calling RequestContextHolder.setRequestAttributes() with a new GrailsWebRequest. The downside to this is that the response object also has to be overwritten. This is not a big problem however, as it is manipulated "in-place" when calling render(), so we can just check the "would be" response status on our newly created object. My Spock test now looks like this:

            Source https://stackoverflow.com/questions/70123280


            Upgrade to Spring Boot 2.4 break Spock Spring mocks
            Asked 2021-Nov-19 at 14:29

            I'm upgrading a Spring Boot application from 2.3.10.RELEASE to 2.4.12. The tests have been written with Spock 2.0-groovy-3.0.

            When I run the following example integration test in Spring Boot 2.4 (that worked in 2.3)



            Answered 2021-Nov-19 at 14:29

            After some research I have stumbled over the following setting that needs to be applied to the application-test.properties or application-test.yml file.

            Source https://stackoverflow.com/questions/70006649


            Verify Spock mock asynchonous interaction after an exception is thrown
            Asked 2021-Nov-19 at 13:35

            I am trying to use a Blocking Variable to verify an asynchonous interaction after a collaborator's method fails. This is what I got:



            Answered 2021-Nov-18 at 18:57

            The thing that breaks you code, is that mock interactions are the first thing that is evaluated in every then block, even if you list other things first. So for it to work, you need to use a second then block as explained in the chapter invocation order in the docs. Since, the mocks are evaluated first, the execution doesn't even reach result.get() that would wait long enough so that the save interaction could be triggered.

            This should fix your problem:

            Source https://stackoverflow.com/questions/70023298

            Community Discussions, Code Snippets contain sources that include Stack Exchange Network


            No vulnerabilities reported

            Install spock

            You can download it from GitHub.
            You can use spock like any standard Java library. Please include the the jar files in your classpath. You can also use any IDE and you can run and debug the spock component as you would do with any other Java program. Best practice is to use a build tool that supports dependency management such as Maven or Gradle. For Maven installation, please refer maven.apache.org. For Gradle installation, please refer gradle.org .


            Spock is supported for Java version 8+. Spock is supported for Groovy versions 2.5 and 3.0. The tests are testing Spock with the specific versions (variants) of Groovy and Java. Default Groovy version is 2.5.
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries
          • HTTPS


          • CLI

            gh repo clone spockframework/spock

          • sshUrl


          • Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link