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
10
votes
2 answers

MockWebServer: java.lang.NoSuchMethodError

Trying MockWebServer for the first time on a Groovy/Spring project that uses Spock for unit testing. I added MockWebServer dependencies as directed (I had to add the second line myself to avoid errors, but it's not…
user3303372
  • 761
  • 1
  • 10
  • 21
10
votes
3 answers

Spock: Reusable Data Tables

Can I take a test like this and extract the where clause data table into a reusable block? @Unroll void "test that doSomething with #a and #b does not fail"(String a, String b) { when: doSomethingWithAandB(a, b) then: …
10
votes
2 answers

How to integration test auto configuration for a custom Spring Boot style starter library?

I am writing a library to provide some functionality that is shared between multiple different Spring Boot applications that I work with. I would like to do something similar to the auto-configuration that is provided by the many Spring Boot starter…
Joseph Downing
  • 1,099
  • 2
  • 12
  • 25
10
votes
1 answer

Integrate Spock's test with Sonar

I use spock to write test case and jenkins to run and publish my test cases. I was able to get the code coverage reported but sonar shows me only Java Unit test cases; the groovy test cases are totally missing The following pom.xml is used as…
harry
  • 310
  • 3
  • 15
10
votes
1 answer

Spock - extracting interactions to method

The spock documentation points out that you can extract assertions of then block to other method and add assert keyword before each assertion. I would also like to extract interactions to helper method. I tried wrapping interactions with…
user3364192
  • 3,783
  • 2
  • 21
  • 30
10
votes
4 answers

Array assertion in Spock

I have a list of some objects - let's assume companies. Now I want to check if this list contains companies with some names but not taking order into consideration. Currently I'm using such construction: companyList.name.sort() == ["First",…
Jakub Kubrynski
  • 13,724
  • 6
  • 60
  • 85
10
votes
4 answers

Java test class with many private methods

I have a class that has the responsibility of importing contracts from a CSV to database. The class itself has only one public method that starts the import and the other methods are all private (because only the class itself will use, and they hold…
Kennedy Oliveira
  • 2,141
  • 2
  • 20
  • 25
10
votes
1 answer

Grails java.io.File mocking

Is there any way to mock a file for unit testing in Grails? I need to test file size and file type and it would help if I could mock these. Any link to a resource would help.
Akolopez
  • 334
  • 1
  • 4
  • 14
10
votes
4 answers

Verify Spock mock with specified timeout

In Mockito there is option to verify if mock method has been called, and specify timeout for this verification (VerificationWithTimeout), for example: verify(mock, timeout(200).atLeastOnce()).baz(); It there any equivalent to such functionality in…
Jakub Kubrynski
  • 13,724
  • 6
  • 60
  • 85
10
votes
2 answers

How to test Grails service using Spock?

I have a EncouragementService.groovy with following method class EncouragementService { def stripePaymentService def encourageUsers(List users){ if(null != users && users.size()>0){ for(User user : users){ //logic …
prayagupa
  • 30,204
  • 14
  • 155
  • 192
9
votes
1 answer

Testing thread concurrency with Spock

Is there a spock equivalent of TestNG's @Test(threadPoolSize=n) that will allow me test the execution of a test, with multiple threads concurrently? Basically, given a specification like so... class SampleSpec extends Specification { def "test…
GroovyBee
  • 275
  • 3
  • 10
9
votes
2 answers

How to give System property to my test via Kotlin Gradle and -D

When I run a test in Gradle I would like to pass some properties: ./gradlew test -DmyProperty=someValue So in my Spock test I will use to retrieve the value: def value = System.getProperty("myProperty") Im using the kotlin gradle dsl. When I try…
2hardproblems
  • 225
  • 2
  • 7
9
votes
2 answers

What is limiting the number of active workers in a Gradle build?

I am trying to run tests in parallel on my laptop, which has 4 pyhsical and 8 logical CPUs. ➜ sysctl -n hw.ncpu 8 ➜ sysctl -n hw.physicalcpu 4 I would like to run at most 4 tests in parallel. This is the command that I am running: ./gradlew…
Thomas Hirsch
  • 2,102
  • 3
  • 19
  • 39
9
votes
1 answer

Groovy 2.5.0 gives noclassdeffounderror for methodcalltransformation

When I upgrade my project from Groovy 2.4.* to Groovy 2.5.0, it gives noclassdeffounderror for org/codehaus/groovy/ast/methodcalltransformation when compiling using Gradle. It works fine in Groovy 2.4. Posting the whole exception…
9
votes
2 answers

Spock: Return input parameter in Stubs

Given an method with a parameter in Java, e.g. public class Foo { public Bar theBar(Bar bar) { /*... */ } } When stubbing/ mocking foo, how do I tell it to accept any argument and return it? (Groovy) def fooStub = Stub(Foo) { theBar(/*what…
user3001
  • 3,437
  • 5
  • 28
  • 54