spock Questions

2

Solved

I do have a simple class like this: package com.example.howtomocktest import groovy.util.logging.Slf4j import java.nio.channels.NotYetBoundException @Slf4j class ErrorLogger { static void handl...
Lyon asked 29/7, 2014 at 18:27

3

Solved

Trying to broaden the appeal of Spock at work and run into this issue. Actually trying to write Unit Tests for a Groovy class, but one that calls out to Java. A static method calls a private constr...
Millepore asked 17/1, 2014 at 19:44

2

Solved

I am using spock to test Java Spring Boot code. It gets a logback logger over the lombok @Slf4j annotation. Dummy class with log call import lombok.extern.slf4j.Slf4j; import org.springframework....
Whimsical asked 11/4, 2018 at 9:52

7

Solved

How can exceptions be tested in a nice way (e.g. data tables) with Spock? Example: Having a method validateUser that can throw exceptions with different messages or no exception if the user is val...
Andriette asked 4/10, 2013 at 15:54

4

Solved

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(...
Physiography asked 10/2, 2014 at 0:0

4

Solved

There is not much to add, the whole question is in the title. Consider these two instances of class Foo used in a Spock specification. @Shared Foo foo1 = new Foo() static Foo foo2 = new Foo() ...
Nichy asked 10/3, 2016 at 17:49

3

Solved

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"...
Enalda asked 21/10, 2013 at 11:48

3

Solved

I test Java code with Spock. I test this code: try { Set<String> availableActions = getSthAction() List<String> goodActions = getGoodAction() if (!CollectionUtils.containsAny(avail...
Nenitanenney asked 31/3, 2014 at 8:36

1

Solved

We are not able to run test cases written with Junit 5 and Spock framework together in one gardle project? We tried add dependencies given in https://www.baeldung.com/junit-5-gradle to our gradle...
Turnaround asked 21/8, 2019 at 6:6

2

Solved

I am in the process of upgrading to grails 2.1.x, and need to redo some of my old-style tests. I just added a new test to my spock Spec, and for this test I need to mock an additional Domain class...
Broadcaster asked 8/4, 2013 at 8:5

2

Solved

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 er...
Ferretti asked 2/7, 2019 at 14:18

1

I was trying out Spock and encountered an interesting problem when writing controller-tests. WebMvcTest(value = SomeController.class) @AutoConfigureMockMvc @ActiveProfiles(value = "restapi") @Imp...
Upcast asked 6/3, 2019 at 10:9

2

Solved

I have a very simple test as blow: def "setContent_activity_finished"(Status editStatus) { // Variables......................... given: activity.getStatus() >> editStatus.toString() wh...
Raze asked 8/9, 2014 at 14:55

2

Solved

I am using Jacoco for unit test code coverage. Jacoco's generated report shows that few branches are missed in my Kotlin code. I noticed that the coroutine code and the code after it, is not proper...
Arrowy asked 26/11, 2018 at 16:31

1

I have a controller like this one: @RestController @RequestMapping('/v1/document') class DocumentV1Controller { @PutMapping HttpEntity<Document> newdoc( @RequestHeader Map<String, Stri...
Shofar asked 18/5, 2016 at 16:19

2

Solved

I'm using Spock and my class to test is wrapped in a Spy. I want to isolate the method being tested, so I'm trying to stub out other methods that are called from the method being tested. Normally I...
Presidency asked 28/2, 2017 at 15:25

1

Solved

I'm using Spock to unit test a service in my app. Recently I encountered a weird behavior I don't really understand. Here is my unit test: def setup() { parkingSessionRepository = Mock(ParkingSe...
Replacement asked 5/11, 2018 at 12:9

2

Solved

I am trying to write some tests for my Spring Boot 1.4.0 with Spock and my application-test-properties file is not being picked up. I have this in my gradle: dependencies { compile('org.springf...
Thereafter asked 23/7, 2016 at 17:45

1

Solved

I have following Java class: import org.apache.commons.lang3.builder.EqualsBuilder; public class Animal { private final String name; private final int numLegs; public Animal(String name, int...
Headline asked 28/9, 2018 at 12:56

2

In a feature method, one specifies the feature action in a when: block, the result of which gets tested in a subsequent then: block. Often preparation is needed, which is done in a given: clause (o...
Plum asked 13/11, 2014 at 9:31

3

Solved

I am trying to mock the one of static method readAttributes using groovy's metaClass convention, but the real method get invoked. This is how I mocked the static function: def "test"() { File fi...
Bristol asked 26/4, 2016 at 13:56

2

I'm wondering how I can mock some private variable in a class with Groovy/Spock. Let's say we have this code: public class Car { private Engine engine; public void drive(){ System.out.println...
Dustindustman asked 15/3, 2018 at 17:3

2

Solved

I'm not really familiar with Spock, so I will be appreciated for some hints. I have a list of custom objects. I want to check that this list contains any number of objects where some of the fields ...
Hibernia asked 8/7, 2018 at 12:56

2

I have created a new Grails 3.1.4 angular project along with a few domain objects and controllers extending RestfulController. I have created the Integration test below. When I run grails test-app ...
Obstinate asked 30/3, 2016 at 12:10

3

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 thro...
Mayo asked 10/12, 2015 at 14:8

© 2022 - 2024 — McMap. All rights reserved.