Questions tagged [spock]

Spock is a testing and specification framework for Java and Groovy applications. The highly expressive specification language makes it easy to create and maintain the code.

Spock is a testing and specification framework for and applications. The highly expressive specification language makes it easy to create and maintain the code.

The Spock framework is compatible with most IDEs and build tools and the specifications can be run and checked from inside your IDE. As long as it can run , it can run Spock.

Getting Started:

Testing Tutorials:

Github Examples:

2357 questions
0
votes
2 answers

Access Spock data provider variable from inside where: block

I'm trying to access a where block variable from within the where block and it is not working. I'm thinking Spock doesn't allow this, but thought I'd give it a shot and see if anyone knows how to do it. where: testNumber << Stream.iterate(1, n ->…
nasch
  • 5,330
  • 6
  • 31
  • 52
0
votes
1 answer

What is the reason for the Spock recursion?

I'm using Spock Framework to write controller tests. Everything is mocked, therefore no calls to third parties. However, I'm getting a Stack Overflow error as below while running this test due to a recursion within Spock…
Nipun Thathsara
  • 1,119
  • 11
  • 20
0
votes
0 answers

unable to resolve class com.homeaway.devtools.jenkins.testing.JenkinsPipelineSpecification

I am trying to run some spock tests with Maven. I already ran tests before with groovy version 2.4. Now when I switched to 2.5+, it shows some error. My minimal pom is: org.codehaus.groovy
0
votes
1 answer

Spock- Groovy call same client multiple times and assert the result

I am trying to test rate-limiter logic, it should result with too many request at the 6th trial I want to get rid of the repetition of calling service 5 times and asserting 200 for the first 5 trial, but no luck, there is an exception Groovyc:…
curious
  • 231
  • 3
  • 12
0
votes
1 answer

Spring Data JPA Specifications AND operation of predicates unit test not excepted or covered

I have written unit tests for my class and they seem to run fine. But the challenge is I can't get full coverage or get the builder.and(...) operation part to execute or be covered. Any idea what could be going on? Thank you This is the utility…
Denis Kisina
  • 350
  • 4
  • 19
0
votes
1 answer

nu.studer.credentials does not work from inside Spock

I am building a Gradle plugin that requires a username and password for the access to an external resource; to avoid clear text passwords, I use the plugin nu.studer.credentials. To test my plugin, I use Spock; the following test file…
tquadrat
  • 3,033
  • 1
  • 16
  • 29
0
votes
1 answer

How to verify method calls in where clause of spock test for a recursive method

Let's say my class is Foo with a recursive method bar which calls a service like below public class Foo { private DataService service; public void perform(int count, final SomeObject obj) { if(count > 0) { …
Rupesh Vislawath
  • 125
  • 1
  • 11
0
votes
1 answer

Mock static method in spock

I try to mock static method with mockito-inline in spock given: try(MockedStatic mockedStatic = Mockito.mockStatic(CryptoUtils.class)){ mockedStatic.when({ -> CryptoUtils.decryptWithPrefixIV(any() as String, any() as…
Ayshan Rzayeva
  • 137
  • 2
  • 11
0
votes
0 answers

In STS - The type groovy.transform.Generated cannot be resolved. It is indirectly referenced from required .class files

I am trying to use spock framework in STS. But I am facing this error in my groovy class. ERROR - The type groovy.transform.Generated cannot be resolved. It is indirectly referenced from required .class files let me know, how to fix this…
0
votes
0 answers

How to mock a feign client call in configuration class

I'm using a spring boot application and some feign clients to reach endpoints from a backend. I'm using a specific client to get a JWT token for authentication and I decided to call this client in a configuration class to create a bean from my JWT…
Mister Mow
  • 31
  • 3
0
votes
1 answer

Test lambda function with spock

@CustomLog @Data @Configuration @RequiredArgsConstructor public class PersonalizationTasks { private final CmdUtils cmdUtils; @Value("${cmd.task-defaults.personalization-service-type}") private String version; …
Ayshan Rzayeva
  • 137
  • 2
  • 11
0
votes
2 answers

How to mock the value of variable inside a class using Spock

Test Class Class TestClass{ @Autowired AnyClass anyClass boolean testMethod() { boolean result = anyClass.method() if(result) { return !result } else { return !result } …
0
votes
1 answer

Set field of mock class without setter

I want to test this method with spock public class MainService { private final DLCRDDLPortType dlcrddlPortType; public void startProcess(Application app) { Holder status = new Holder<>(); …
Ayshan Rzayeva
  • 137
  • 2
  • 11
0
votes
0 answers

Spock data driven tests + surefire rerunFailingTestsCount gives false positive test results

Here is an always failing data-driven spock test: class HelloSpockSpec extends Specification { def "test"() { expect: 1 == number where: number << [2, 3] } } When this test is ran from maven, as expected, it executes 2 times,…
streetturtle
  • 5,472
  • 2
  • 25
  • 43
0
votes
1 answer

How to write test case for Spring boot controller using spock framework

I have written a simple rest application using Spring boot, now I want to write a unit test case for my controllers using the Spock framework. I already tried like this , but it did not Succeed My controller class public class AbcController extends…
hansika
  • 79
  • 1
  • 6