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: If I update Spock to a more recent version (eg. 2.1-groovy-2.5) I get this error: I am using Java 11 and Maven 3.6.3. My pom.xml is rather long, so I’ve reduced…
Tag: spock
How to mock a class that has a method that returns nothing, using Spock
I am currently attempting to set up Spock testing for a class that I created that has a method that returns nothing. Above is the test I want to Spock test, and I only want to test this class and not the Handler class that has the method getValues. This is my test mock class: But I get a null
Can I add a delay to a call to a Stub method in Spock?
I’m using the Spock Framework to test some Java classes. One thing I need to do is add a delay to a Stub method that I’m calling, in order to simulate a long-running method. Is this possible? This looks possible using Mockito: Can I delay a stubbed method response with Mockito?. Is it possible usi…
How to test a service or do it right mock? Java11, Spock Framework
Colleagues, I welcome you all! Tell me how to decide, or how to act. (Java11, SpringBoot, testing – Spock Framework) I need to write a test that will test a class method, the whole problem is that the method of the class under test calls another service through inheritance, which is not declared in the …
Data from test with @Transactional are persisting between tests
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…
Spock Error:Groovyc: Could not instantiate global transform class
I m new to Spock, tried to write a simple Spock but it failed: here is my Spec: and here is my pom.xml: what is wrong my Spec or pom setting? do i have to install Groovy to make it work? Answer Here is your test, re-written in more idiomatic Spock/Groovy: A couple of notes: Groovy (in which Spock tests
Spock throw exception test
I test Java code with Spock. I test this code: I wrote test: And it fails because AnotherCustomExceptio is thrown. But in the try{}catch block I catch this exception and throw a CustomException so I expected that my method will throw CustomException and not AnotherCustomExceptio. How do I test it? Answer I be…