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
12
votes
1 answer

Spock + GEB vs. Robot Framework

Previously I used Robot Framework to automate testing of applications, but a new client asked pay attention to Spock + GEB. I've never used it, but I need to quickly compare two of these tools and make a choice. Please help me to understand how they…
Evgeniy
  • 540
  • 4
  • 17
12
votes
4 answers

Execute some action when Spock test fails

I'd like to execute some action when Spock test fails. Specifically, take a screenshot. Is it possible? How to do it?
amorfis
  • 15,390
  • 15
  • 77
  • 125
12
votes
2 answers

Inject dependencies in Grails Spock Specification test

I need to get the dependencies injected in my domain objects in my tests. This tests are placed in the test/integration directory and extends from spock.lang.Specification. How can I achieve this? Note: I've seen this post How to inject spring beans…
Tomas Romero
  • 8,418
  • 11
  • 50
  • 72
11
votes
1 answer

Spock vs FitNesse

I've been looking into Spock and I've had experience with FitNesse. I'm wondering how would people choose one over the other - if they appear to be addressing the same or similar problem space. Also for the folks who have been using Spock or other…
KumarM
  • 1,669
  • 1
  • 18
  • 26
11
votes
2 answers

How to test a Grails Service that utilizes a criteria query (with spock)?

I am trying to test a simple service method. That method mainly just returns the results of a criteria query for which I want to test if it returns the one result or not (depending on what is queried for). The problem is, that I am unaware of how to…
user569825
  • 2,369
  • 1
  • 25
  • 45
11
votes
1 answer

All possible permutations of parameters using Spock's Unroll

I have the following parameters for the same test: a | b | c 1 | 2 | 3 11 | 22 | 33 Spock provides the @Unroll annotation for tests similar to this (with this set of parameters you can run to same tests with the vectors [1, 2, 3] and…
Dmitry Senkovich
  • 5,521
  • 8
  • 37
  • 74
11
votes
1 answer

"Empty test suite." in pure kotlin module. (Spock/Android)

My android app is multi module project: include (android-app/kotlin-android)':application', (pure kotlin)':presentation', (pure kotlin)':domain', (android-library/kotin-android)':dataproviders' Modules :application and :dataproviders working fine…
Hype
  • 1,039
  • 1
  • 10
  • 27
11
votes
1 answer

Spock verifying an exception thrown by mock together with mock interaction

The problem I encountered is when I try to verify in the then block that an exception has been thrown, and that call on a mock has been made. Look at the setup below: class B { def b(A a) { a.a() } } class A { def a() { …
jarzeb
  • 113
  • 1
  • 1
  • 5
11
votes
2 answers

Intellij IDEA fork mode for unit tests slows down

I'm running 9 JUnit (Spockframework actually) tests in Intellij IDEA. It takes about 3 seconds. I want to make use of all of the cores, therefore I switch test configuration fork mode - class. Edit configurations > Fork mode > class This causes…
Wojtek Erbetowski
  • 3,205
  • 5
  • 22
  • 37
11
votes
2 answers

Grails spock tests with private methods failing after upgrading to 2.5.0

We've upgraded our app from Grails 2.4.4 to 2.5.0. All are working fine, but some test cases are failing which containing some private methods. import org.junit.Before class UserServiceSpec extends IntegrationSpec { @Before def setup() { …
Shashank Agrawal
  • 25,161
  • 11
  • 89
  • 121
11
votes
2 answers

Using Spock to mock private static final variables in Java

I'm trying to write some Spock tests with Groovy to test some Java code (specifically a servlet Filter). I have some private static and private static final variables that I would like to mock, but I can't determine if there is a way to do this. I…
mnd
  • 2,709
  • 3
  • 27
  • 48
11
votes
1 answer

Spock Test, only check if method is called and do not execute it

In our Spock tests we want to check if the correct path in our software is selected. But we do not want to test the function of the methods which are called (this is done in separate tests) def "Test"() { setup: service.metaClass.innerMethod…
Alexander Kiefer
  • 546
  • 1
  • 13
  • 30
11
votes
3 answers

Using PowerMock with Spock

I have a class with a few static methods.I need to Mock these static methods. I know PowerMock does this,but I was not able to find any tutorials/materials that shed some light on "Spock+PowerMock" integration. I prefer Spock to Junit,hence the…
Avinash
  • 347
  • 1
  • 4
  • 15
11
votes
5 answers

How can I repeat Spock test?

As described here @Repeat annotation is not supported right now. How can I mark spock test as repeated n times? Suppose I have spock test: def "testing somthing"() { expect: assert myService.getResult(x) == y where: x | y 5 | 7 …
fedor.belov
  • 22,343
  • 26
  • 89
  • 134
10
votes
2 answers

How to inject spring beans into spock test

I am new to spock. I am trying to write a spock unit test against a standalone java app that uses JDK 1.7, Spring 3.1, Groovy 1.8.6, Spock 0.6, Maven 3.0.4. A basic hello world spock test is working. However when I try to test spring beans, I find…
arrehman
  • 1,322
  • 6
  • 31
  • 42