Skip to main content
How are we doing? Please help us improve Stack Overflow. Take our short survey
Filter by
Sorted by
Tagged with
0 votes
0 answers
32 views

How to write a Spock test case for handling invalid JSON response in Spring? [closed]

I have a class that handles HTTP responses, and it uses response.close() to close the response stream. However, during mutation testing, the call to response.close() is removed, leading to a "...
Chetooo's user avatar
  • 29
1 vote
1 answer
20 views

Dynamically append value to spock test method name based on method annotation

We have a large Spock test suite, across mulitple teams, each teams tests have an annotation on them such as @Team5. I would like to append - @Team5 dynamically to the end of each test methods name ...
Nate Muller's user avatar
0 votes
1 answer
27 views

How to mock interaction from method outside of Spec in Spock

I have a mocked object userService = Mock() and a mocked interaction userService.test("test") >> "result" How can I define this interaction in another class/method ? Maybe &...
Sebastian Dusza's user avatar
-1 votes
0 answers
27 views

Can't define the behaviour of a Mock in Spock [duplicate]

I'm trying to define the behaviour of a Mock in spock but it's not working, i looked to te documentation text and still got it wrong. This is what my test is doing, if the function isCharge() in the ...
Luis Santos's user avatar
0 votes
1 answer
38 views

How to mock with Spock

I want to mock with Spock a method getEntity for the Spring ResTemplate Product getProducts(ProductSearch request) { Map<String, Object> queryParam = new HashMap<>(); queryParam.put(&...
BreenDeen's user avatar
  • 738
-1 votes
1 answer
99 views

Spock Mock Not Working, Test Throws NullPointerException

I have a problem with mocking in the spock, my variabla systemTaskOptional is null, test throwing an error. Here is my code of test, and part of code with biznes logic, where is null throwing. def ...
Karol Wolny's user avatar
1 vote
1 answer
386 views

Spock happens exception:Too few invocations for: xxxx Unmatched invocations (ordered by similarity)

I use Spock to test my java code,in detail to test method is MnsTemplate's sendMessage Method and unit test is in MnsTemplateTest, they are in below code. In this unit test, I mock MNSClient�?...
user27846561's user avatar
2 votes
1 answer
20 views

Grail, GORM, Spock: An association from the table [X] refers to an unmapped class: [Y]

I'm getting this error in a Spock test after adding a new association to one of the domain objects that this service uses. I haven't found any Grails-related or GORM-related questions referencing this ...
SGT Grumpy Pants's user avatar
0 votes
1 answer
56 views

Test SpringBoot Webclient in Groovy throwsNullPointerException in put call

I am testing a Java method that uses Spring Boot WebClient to make a PUT request and returns void. The test is written in Groovy. This is the method I want to test: public void putProcessing(final ...
oitathi's user avatar
  • 175
0 votes
1 answer
41 views

How to use database methods in grails spock specification tests?

I am going to test some classes test using specification test with spock. Some methods uses Domain.list() and it not available via light specification test. Of course I could replace Domain.list() ...
user2572790's user avatar
1 vote
1 answer
51 views

How to mock random static method: RandomStringUtils.random

I have following easy file random.groovy in "vars" folder and Im trying to test with groovy 2.4 and spock testframework 1.3-groovy-2.4. The file is basically about generating random ...
Nikolai Ehrhardt's user avatar
0 votes
1 answer
100 views

Mock new Date or System.currentTimeMillis

I am setting up tests using Groovy and the Spock framework. My tests depend on the passage of time, and the services in question use new Date() for some rules. Because of this, I would like to modify ...
felipe mota effting's user avatar
0 votes
1 answer
54 views

HTTP Connection Error in cleanupSpec() Function in Spock: "SSL is disabled"

I'm encountering an issue when making an HTTP request in the cleanupSpec() function of a Spock test. The same HTTP GET request works perfectly in both the test case and the cleanup() function, but ...
MathProblem's user avatar
0 votes
1 answer
54 views

Spock mocking for exception causing code coverage issue

I have below code which I am trying to tests for in Spock Class Validator{ String envCheck(String environment) { if (environment == null || environment.isEmpty()) { new ...
Umesh Kumar's user avatar
  • 1,387
0 votes
1 answer
75 views

Spock - issue with assertions when using placeholders in GString

I have an issue with Spock, getting an assertions error when comparing identical Strings. my test case: def "should return error when email already exists in company"() { given: "A ...
Dariusz Urbanek's user avatar
-1 votes
1 answer
76 views

How can I configure JerseyTest with Spock in Spring Boot Application for Unit Tests?

I want to test the next controller class using Jersey Test in my Spring Boot application. Controller Class @RestController @RequestMapping("/api/v1/demo") public class UserController { ...
Alex_Pap's user avatar
  • 454
0 votes
1 answer
66 views

Group (or merge) @Unroll tests from Spock in JUnit XML result file

I have a Spock @Unroll test like this: @Unroll def 'A session uses the TLS protocol #enabledProtocolsOfSocket #protocolOfSession'() { given: // ... expect: // ... where: ...
crusy's user avatar
  • 1,512
0 votes
1 answer
49 views

How to correctly verify mock method invocation in Spock framework?

I'm trying to test a method using the Spock framework, but I'm running into an issue when verifying the mock method invocation. Here's my code: package com.workato.agent.smb import spock.lang....
diziaq's user avatar
  • 7,775
0 votes
0 answers
52 views

When I perform spring-boot unit testing, the spring datasource is repeatedly initialized

I'm using Groovy + Spock to perform unit testing for a Spring-boot project. I have two test classes, Test Class A and Test Class B. These two test classes are independent and have no dependency ...
Mike Wu's user avatar
0 votes
2 answers
225 views

How to mock HttpClient using Spock-framework

The following method is providing instances of java.net.http.HttpClient: @CompileStatic private static HttpClient getClient() { return HttpClient.newBuilder() .version(HttpClient....
john's user avatar
  • 613
-2 votes
1 answer
58 views

Mocking ProductCategory findAll fails in Groovy Spock test

I have a class which associates Products with a ProductCategory. It uses a ProductCategoryRepository which is a MongoDB repository. The ProductCategoryRepository has a findAll methods which takes the ...
BreenDeen's user avatar
  • 738
0 votes
0 answers
89 views

Rest assured basic authentication scheme does not work anymore

I have been working on upgrading one of our microservices to Spring Boot 2.7.8 -> 3.1.5 during this activity I encountered a problem when it was not possible to set AuthenticationScheme in ...
Peter S.'s user avatar
  • 591
1 vote
1 answer
120 views

Update Spock mock from different threads

I am testing code that runs in its own thread in a while loop. The code under test does some stuff based on the current time, then updates an AtomicReference<Integer> The application logic is an ...
James Wierzba's user avatar
-1 votes
1 answer
125 views

Connection Closed when Testing Repository using Testcontainers with JDBC Template

I am trying to test the below UserRepositoryImpl class that inserts a User into a MySql database. @Repository public class UserRepositoryImpl implements UserRepository { private final ...
Alex_Pap's user avatar
  • 454
1 vote
0 answers
634 views

org.junit.platform.commons.JUnitException: TestEngine with ID 'spock' failed to execute tests

I am having one java project in which added groovy test cases and I uses below: maven dependency. <!-- https://mvnrepository.com/artifact/org.spockframework/spock-core --> <dependency&...
user25113687's user avatar
0 votes
0 answers
30 views

Groovy bounded range isn't excluding the first value

According to Mr. Haki, Groovy 4 supports excluding the first value from a range construction. However, when I run the below Spock test, the first value printed is 0, not 1. What is going on here? ...
spartanhooah's user avatar
1 vote
1 answer
74 views

Verify @KafkaListener has been called after Kafka producer send in Spock

I have a Spring consumer with @KafkaListener: @Service @Slf4j public class EventListener { @KafkaListener(topics = "topic", groupId = "group-id") public void consumer(...
Ali Malek's user avatar
  • 722
0 votes
1 answer
147 views

Looks like my test doesn't wait for subscription - webflux, spock, stepVerifier

I simplified my problem to this pseudo code. My controller @RestController @RequestMapping("api") @RequiredArgsConstructor public class TestController { private final Service service; @...
Bolek Lolek's user avatar
0 votes
0 answers
48 views

The security token included in the request is invalid in @WebMvcTest

When i'm trying to test simple controller call mockMvc.perform(post("/api/v2/test-flow/{key}", key) .contentType(MediaType.APPLICATION_OCTET_STREAM) .content(...
Ivan Karotki's user avatar
0 votes
1 answer
52 views

Spock Mock not updating the fields

Suppose we have a class that we want to mock. class Apple { Color color bool isFresh } We mock it with Mock. We execute the code we need to test. Mocked Apple object gets its Color color updated. ...
Mike U's user avatar
  • 237
0 votes
2 answers
1k views

NoSuchMethodError: 'java.util.Set org.junit.platform.engine.TestDescriptor.getAncestors() when running Spock Spring Boot unit tests

Context I have a unit test written using the Spock Testing framework to test my Spring Boot application. I've declared the following test dependencies: spock-spring: 2.3-groovy-4.0 spring-boot-...
roj's user avatar
  • 1,373
0 votes
1 answer
180 views

Generate ascii doc api documentation from spring rest docs using Spock

I'm trying to write Spock test cases for my Spring Boot application (version: 2.7.5), and I want to generate AsciiDoc documentation using Spring REST Docs. Can someone provide a sample working code ...
vamsi's user avatar
  • 25
0 votes
2 answers
87 views

Spock temporary directories in data-driven test fail after first case

I am using Spock to test some code (Spring app) that involved saving data to disk. I need to test more than one case, so I am using where: keyword to plan multiple test cases. The tested code saves ...
rafal.sz's user avatar
-2 votes
2 answers
96 views

Moving from Spock 1.3 (groovy 2.4) to 2.x (groovy 4.0) Spy no longer work for constructors requiring args

In Spockframework 1.3 the following works for spy and then the spied object creates a closure MyClass is the closure's delegate. In Spock 2.0, the closure doesn't set MyClass as its delegate. ...
Peter Kahn's user avatar
0 votes
1 answer
44 views

spock / groovy always return null as callable result

How to reproduce def 'test of java lambda' () { given: Callable<String> working = () -> {return "working"} and: def executor = Executors....
Krzysztof's user avatar
  • 2,072
0 votes
1 answer
71 views

Spock Mock doesnt work inside lambda function

I can't find something about it, but it seems like the Spock mock doesn't work inside my lambda function. I have tried: RestTemplateAdapter restTemplateAdapter = Mock(RestTemplateAdapter) int ...
Myphre's user avatar
  • 13
0 votes
1 answer
283 views

JaCoCo coverage with SpockFramework + groovy is incomplete

Given a case statement with a default a unit test for this When IDEA, runs coverage tests, the lines show as covered. When gradle+jacoco creates the reports, the lines show as not covered. Copilot ...
Peter Kahn's user avatar
0 votes
1 answer
42 views

No tests found for given includes: [com.bright.TwitterAnalog.AuthenticationControllerSpec.Register user with valid request](--tests filter)

I have this build.gradle file plugins { id 'groovy' id 'org.springframework.boot' version '3.2.4' id 'io.spring.dependency-management' version '1.1.4' } group = 'com.bright' version = '0....
Bright's user avatar
  • 95
0 votes
0 answers
39 views

Spock testing framework Unroll all tests to the parent class , when using EmbeddedSpecRunner and display in test execution report

I am using EmbeddedSpecRunner to iteratively call tests from within a test . Though it runs successfully, I am not able to get each of the tests that were executed in the final Unroll. Only the parent ...
Romasha's user avatar
  • 21
0 votes
1 answer
41 views

Spock stubbing not working as expected. Stubbed method returning null instead of mock response

I am trying out spock framework for writing unit test for a particular method in a service class but not able to mock response for a method. Service class @Service @RequiredArgsConstructor public ...
Ravish Khatri's user avatar
0 votes
1 answer
643 views

Spock test fails, RetrySynchronizationManager.getContext() is null

I wrote a Spock test to exercise a service using Spring-retry, the test context doesn't get setup correctly somehow. The specific error is (line breaks inserted by @kriegaex): [ERROR] ...
Nathan Hughes's user avatar
0 votes
0 answers
45 views

Spring bean loading and test setup method order

Let's suppose there's a test like this: @ActiveProfiles(value = "test") @SpringBootTest(classes = AbcApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) class ...
IceMajor's user avatar
  • 241
0 votes
0 answers
25 views

How to add testing library to Intellij Idea Create Test pop-up [duplicate]

In Intellij Idea when I press CMD+Shift+t I see this: After pressing Enter I see new window with possibility to choose test library If I need to add here Spock framework, how can I do it? Groovy ...
SoulCub's user avatar
  • 467
4 votes
1 answer
661 views

Upgraded IntelliJ and Spock disappeared from Testing Library List

I recently upgraded to IntelliJ 2023.3 and now when I hit Ctrl Alt T to create a test, the Testing Library list includes junits and Test NG, but no spock. I can still run my existing Spock tests, but ...
Thom's user avatar
  • 15k
-1 votes
2 answers
84 views

How to use spock to stub/replace super method in unit test

I've inherited a massive code base and need to add some unit tests, below is a representation of the scenario under test. Given these two classes: package com.foo; public class ExtendableClazz { ...
Jim's user avatar
  • 179
0 votes
1 answer
351 views

Maven - run java and groovy tests

When running mvn test Only java tests are run I want to learn how to run all tests without IDE Output (important part) [INFO] --- gmavenplus-plugin:3.0.0:addTestSources (default) @ project --- [INFO] ...
Rustacean's user avatar
0 votes
1 answer
80 views

IntelliJ Context Suggestions for Missing Method

When using IntelliJ and referencing a non-existent method, normally I would expect the context to suggest "Create Method" and try to use the apparent signature. This used to work in the past,...
Bradley M. Small's user avatar
0 votes
1 answer
355 views

Spring boot gradle integration test with Spock

I am using Spring Boot + Gradle + Spock (groovy) for integration and unit testing. I was able to configure unit tests to work with Spock. Integration tests fail to start because they do not see ...
Evgenii's user avatar
  • 447
2 votes
1 answer
901 views

How to mock bean in springboot groovy and spock tests?

This is a spock test using groovy This is my code @SpringBootTest class SrMetricServiceAspectTest extends Specification { @Autowired @Qualifier("potentialSrCreation") private ...
committedandroider's user avatar
0 votes
2 answers
155 views

Why does my test not work when splitting mocking and stubbing?

I struggle with Spock/Groovy testing. Don't know why but in WHEN section, I cannot check number of calls and checking the value at once.. If I check one of them separatly all works fine! This test ...
michalbarnat's user avatar

1
2 3 4 5
49