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

Testing thread safety fails with Spock

The subject I have some code that is decidedly not thread safe: public class ExampleLoader { private List strings; protected List loadStrings() { return Arrays.asList("Hello", "World", "Sup"); } public…
Martin Lehmann
  • 774
  • 8
  • 15
9
votes
3 answers

Spock/Grails - Groovy:unable to resolve class grails.test.mixin.TestFor and unable to resolve class spock.lang.Specification

I am creating a Spock test for my plugin project-plugin and my main project name is main-project which is using project-plugin as a plugin. So when I am creating a Spock test for my plugin its throwing above error means its warning project-plugin…
user4408375
9
votes
2 answers

How to configure Spock test to load Spring Context (for @Autowired)?

I have such Application class: @Configuration @EnableAutoConfiguration @ComponentScan @ImportResource("classpath:applicationContext.xml") @EnableJpaRepositories("ibd.jpa") public class Application { public static void main(String[] args) { …
Lesya Makhova
  • 1,340
  • 3
  • 14
  • 28
9
votes
1 answer

Getting "Too few invocations" on unit test with spock

For simplicity let's take a very simple class: public class TestingClass { public void method1(){ System.out.println("Running method 1"); method2(); } public void method2(){ System.out.println("Running method…
Aram Aslanyan
  • 745
  • 3
  • 11
  • 18
9
votes
2 answers

How to unit test logging error with Spock framework in groovy

So I have a class that has a method that logs a message: class Car { private Logger logger = LoggerFactory.getLogger(Car.class); void startCar() { logger.error("car stopped working"); } } How can I test that the error was…
letter Q
  • 14,735
  • 33
  • 79
  • 118
9
votes
1 answer

SPOCK - All @Shared Variables are NULL

Here is my test class: import grails.test.mixin.* import spock.lang.Specification import spock.lang.Unroll import spock.lang.* import groovy.util.logging.Slf4j @Slf4j @Mock([PromoRule, PromoCode, SecUser]) @TestFor(PromoService) class…
9
votes
4 answers

Groovy casting collection unasked for it

I have some code written in Java that uses Generics. This is a simple version: // In Java public interface Testable { void test(); } public class TestableImpl implements Testable { @Override public void test(){ …
Parobay
  • 2,549
  • 3
  • 24
  • 36
9
votes
2 answers

Spock GlobalExtension is not loaded (grails)

I want to register a Listener to all spock geb specs in my grails-app so I added a IGlobalExtension to myapp/src/groovy package myapp.spock class TakeScreenshotExtension implements IGlobalExtension { @Override void visitSpec(SpecInfo…
Moritz
  • 489
  • 1
  • 5
  • 18
9
votes
1 answer

Multiple when/then with where for each other

I'm trying to write functional test with Spock and Geb. I want to use in one test method multiple blocks of when/then with where for each block. Is it possible? Or I should use one where for all the when/then?
uladzimir
  • 5,639
  • 6
  • 31
  • 50
9
votes
3 answers

How to make multiple requests with different data in Grails Integration tests

I'm writing a Grails 2.2.1 integration test using the Spock plugin, in which I am trying to post two sets of data to the same controller endpoint: when: "The user adds this product to the inventory" def postData = [productId:…
9
votes
3 answers

JUnit + Maven + Parallel Test Execution Error

I have a problem executing JUnit Tests in parallel when Using JUnit, Groovy, Spock and Maven. When executing them, I get the following after test are passed succesfully: [INFO]…
Sven Ruchti
  • 231
  • 3
  • 5
9
votes
2 answers

How to mock a request when unit testing a service in grails

I am trying to unit test a service that has a method requiring a request object. import org.springframework.web.context.request.RequestContextHolder as RCH class AddressService { def update (account, params) { try { def…
ontk
  • 942
  • 1
  • 10
  • 24
9
votes
1 answer

Learning GEB and Spock

I am a manual tester trying to learn GEB and Spock. To learn these do I have to have prior knowledge of java or groovy? I have been reading the book of GEB, What are the prerequisites, books or learning resources? Please help. Thanks.
Dee
  • 223
  • 5
  • 11
9
votes
2 answers

Spock mocks for Akka's ActorRef

I've tried to make an Spock test for a class, where i need to check that it sends a message to actor (say statActor). I know that Akka have special library for integration test, but seems that it's too much for very simple test. So, i've…
Igor Artamonov
  • 35,450
  • 10
  • 82
  • 113
9
votes
4 answers

Debug Spock tests in Intellij IDEA

I'm running Spock tests by "Right click -> Run -> Test Name". How can I run tests in debug mode? Debug icon run tests but doesn't stop on breakpoints
fedor.belov
  • 22,343
  • 26
  • 89
  • 134