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.
2,314
questions
-1
votes
1
answer
28
views
Groovy, Spock wildcard for varargs, Java 11 [closed]
I'm using the allOf method of CompletableFuture in my service.
public static CompletableFuture<Void> allOf(CompletableFuture<?>... cfs) {
return andTree(cfs, 0, cfs.length - 1);
}
As ...
0
votes
1
answer
44
views
How to ignore tests and log reason in Spock 1.x
I have been writing some tests using Groovy/Spock and came to the need of some decorator/logic that would only run some tests based in a variable's value
I was reading about @IgnoreIf which is the ...
0
votes
2
answers
31
views
When performing unit testing using Spock, JpaRepository is not being injected and is returning as null
During my unit tests using Spock and Testcontainers, the JpaRepository is not functioning properly and is not being wired correctly. This issue persists even in non-integration tests.
As suggested in ...
0
votes
1
answer
24
views
GroovyShell script needs to call local methods
I need to create a Script from a String and execute it in the context of the current test class. Here's my simplified code:
import spock.lang.Specification
class MyTestSpec extends Specification {
...
2
votes
1
answer
29
views
Custom-Webclient Spock test throws unwanted NullPointerException in GET call
Using the custom WebClient below:
@Slf4j
@RequiredArgsConstructor
@Component
public class TransitApiClient {
private final TransitApiClientProperties transitApiClientProperties;
private ...
1
vote
0
answers
34
views
How can I unit test AuthControllerIntegrationTest and mock JwtDecoder in Spock correctly?
I have a spring security Book store api which is working as expected.
My Security Config class look like this.
@Configuration
public class SecurityConfiguration {
@Bean
JwtDecoder jwtDecoder (...
2
votes
0
answers
34
views
LocalFileDetector can't find uploaded files in Selenium Grid tests
I'm using Selenium Grid to run some automated tests that always worked locally. I've created a RemoteWebDriver object, and used remoteDriver.setFileDetector(new LocalFileDetector()) to activate the ...
0
votes
1
answer
40
views
Mocking with Spock returns null for nested mocking and stubbing
I am writing unit tests with Spock for a series of nested objects. The code I'm writing tests for is quite legacy and doesn't use dependency injection. However it is also quite mission-critical so I'd ...
0
votes
1
answer
29
views
How to test method that uses Utility calls and need to return its input?
I have a Java method that looks something like this:
public Map<String <Set<Something>> mathod() {
Map<String, Set<Something>> originalMap = createMap();
return ...
0
votes
1
answer
41
views
How to mock an instance method on injected instance of the class under test?
I am trying to mock an instance method within a real object which is injected within my Test class in spock and I am using Micronaut (with Java) for writing my application. It is as follows:
class ...
0
votes
0
answers
28
views
How to create Spring Service integration test in Spock with MongoDB testcontainer?
Suppose I have a service:
@Service
public class MyService {
@Autowired OtherService otherService;
@Autowired MyRepository myRepository;
// some methods...
}
where myRepository implements ...
2
votes
1
answer
27
views
Maven Surefire Plugin + Spock 2: additional “test case” in the report
With Spock upgrade to 2.4-M1-groovy-3.0 we found out that test reports for our data driven tests (= using @Unroll Spock annotation) contain an additional "test case" and also counts the time ...
0
votes
1
answer
59
views
How to prevent using production MongoDB URI in spock micronaut tests
How can I ensure that my tests will never use the production MongoDB URI in my Micronaut application?
I am currently using an embedded server in my test configuration to run my tests with a test ...
0
votes
1
answer
21
views
Can't see traces in Spock test
I'm trying to put traces into a Spock test to see how the PostgreSQL container was created by the testcontainer. But neither with log4j , nor with prints on the standard output nor by extending the ...
1
vote
0
answers
28
views
micronaut authenticate failing on spock test
I am learning micronaut security, I have created this authenticate method:
@Singleton
class AuthenticationProviderUserPassword implements AuthenticationProvider {
@Inject
UserRepository ...
0
votes
0
answers
13
views
How to add directory to a classpath , I am trying to register IGLOBAL Extension in spock
How to add directory to a classpath ? I am trying to register IGLOBAL Extension in spock.
Not sure about the below step what exactly I should be doing:
Extensions are not discovered automatically, you ...
0
votes
1
answer
19
views
Spock test being Ignored when Spring context cannot start
I have problem with Spring Spock integration.
I have SpringBoot test in Spock which set up Application Context.
If for some reason Spring context is broken (for example missing Autowired dependency) ...
-1
votes
2
answers
49
views
Does the spock test code not prevent the mistake of putting the generated instance as a parameter?
I am testing using the spock framework in groovy language.
I want to test TestService, and TestService uses TestRepository as below code.
@Service
@RequiredArgsConstructor
public class TestService {
...
0
votes
0
answers
19
views
jenkins instance is missing when writing spock test
I am writing a test for which having a Jenkins instance . so I need to mock the Jenkins class and set the instance to Jenkins. What is the method to set the instance?
Import jenkins.model.Jenkins
-1
votes
3
answers
54
views
Mock Spark DataFrameReader .option
I want to parametrice when i have a header and then separator when I read a csv from Spark. I've written this:
DataFrameReader dataFrameReader = spark.read();
dataFrameReader = "csv"....
1
vote
1
answer
60
views
Java - Spock "where" block is not working
I am trying to write some test with where but it seems like the data mentioned in where block is not being passed, (I found the values to be null).
Here is my unit test:
def "method response ...
1
vote
1
answer
45
views
Groovy Spock. How to verify interaction with two arguments method?
Trying to use Spock mocks to verify method invocation arguments.
Documentation and most of the examples in the internet contain example for single argument.
How to implement capture and verification ...
0
votes
1
answer
58
views
Why does this Spring Boot MVC test fail when autowired dependency replaced with interface or abstract class?
This is the Controller as it appears at the moment.
import com.myorg.service.MyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core....
0
votes
1
answer
34
views
How to simulate ReadTimeoutException in Spock with Micronaut
I am trying to simulate io.micronaut.http.client.exceptions.ReadTimeoutException with Spock, but explicitly the exception cannot be thrown, as it cannot be accessed from the test class.
The code which ...
0
votes
1
answer
38
views
Calling entity.delete(flush: true) in a Spock test does not flush, nor does using withTransaction, one has to run both separately
I have a Grails 5.2.5 app with a Spock 2.0 test.
In it, I try to delete an entity like so:
def "experiment"() {
given:
MyEntity entity = new MyEntity().save(failOnError: true))....
0
votes
2
answers
85
views
How to write spock test case for exception handling?
I am learning Spock so this may be very basic.
public Random genRand() {
try {
return SecureRandom.getInstanceStrong();
}
catch (NoSuchAlgorithmException e) {
logger.debug(e.getMessage())...
1
vote
1
answer
40
views
How do I create a detached mock with closure in Spock framework?
It's good to see we can have detached mocks since Spock 1.1, especially if we want to create a mock utilities for boilerplate UT coding.
But it seems DetachedMockFactory refuses to be initialised with ...
0
votes
1
answer
72
views
Cannot resolve import io.micronaut.test.extensions.spock.annotation.MicronautTest dependency on micronaut 1.3.7
I want to add spock testing framework in micronaut but so I added these dependencies in micronaut:
testImplementation "io.micronaut.test:micronaut-test-spock"
testImplementation(&...
0
votes
0
answers
90
views
JUnitException: TestEngine with ID 'spock' failed to discover tests
We are attempting to make some updates to our testing suite. We would like to convert our contract tests that use PACT to use jUnit5.
When we update our packages such as our PACT consumer/provider ...
0
votes
1
answer
166
views
Error occurs occasionally when mock static method in spock
I have written two test classes (CryptUtilTest1.groovy, CryptUtilTest2.groovy) for the same tool class method. I mock StringImplUtils.emptyIfBlank method in CryptUtilTest2.groovy. When the two test ...
2
votes
1
answer
281
views
Spring Boot 3 with testing in Spock doesn't create context in @SpringBootTest test
I created simple project with the newest Spring Boot 3 and spock versions, which you can find here: https://github.com/RafBorkowski/SpringBoot3SpockExample. When I try to start test with junit, ...
0
votes
0
answers
11
views
Grail 4 Spoc framework unit testing - withFilters not working
We use to use withFilters function in Mixin while writing unit tests but it does not support in Grails 4 spoc framework
Please help me if you know what we can use at place of withFilters.
I was using ...
-1
votes
1
answer
140
views
Dynamic WireMock server in groovy test - Junit5
Regarding the article: https://wiremock.org/docs/junit-jupiter/
I tried doing my own server:
@RegisterExtension
static WireMockExtension wm1 = WireMockExtension.newInstance()
....
0
votes
0
answers
64
views
How to Remove Logging Output from Allure 2
I have Java/Groovy/Spock tests and Allure 2 report. I use allure.Step() annotation to describe all steps that I want to see in Allure report. For example:
def "some test"() {
when: "...
0
votes
1
answer
135
views
Junit not running tests in parallel
I have test:
import org.junit.jupiter.api.parallel.Execution // version 5.9.0
import org.junit.jupiter.api.parallel.ExecutionMode
import spock.lang.Specification
import spock.lang.Unroll
@Execution(...
0
votes
1
answer
26
views
Micronaut test: Execution failed for task ':compileTestGroovy'. > java.lang.ExceptionInInitializerError
I am new to micronaut and I am trying to implement spock test on my project. I am currently using micronautVersion=2.5.13 and I am having my tests in src/test/groovy/{package_name}. I am trying to run ...
0
votes
1
answer
174
views
Writing Unit Test of Interceptors
I am working on a project where I need to write an interceptor which basically modifies headers. Below is a similar code
class AuthRequestInterceptor implements Interceptor {
@Override public ...
0
votes
1
answer
64
views
How to add unit test for enum in spock?
I am having below enum class
public enum EmployeeType {
PERMANENT("10"),
TEMPORARY("20"),
PART_TIME("30");
private final String employeeTypeId;
...
1
vote
2
answers
90
views
Testing my annotation based myBatis mapper, using Spock and groovy, SpringBoot
I created myBatis mapper based on annotations as this changed code example:
import org.apache.ibatis.annotations.*;
import java.util.List;
@Mapper
public interface MyTableMapper {
@Insert("...
1
vote
0
answers
74
views
Creating method for only tests purpose in Mappers interface (myBatis)
I found this question! But, this not solve my Question!
How to create method that could be used only for tests
Firstly for myBatis Example:
import org.apache.ibatis.annotations.*;
@Mapper
public ...
7
votes
2
answers
118
views
How to mock a service with spock in micronaut when testing a rabbit consumer?
I'm currently working with:
Micronaut 3.7.3
RabbitMQ 3.11.2
Spock
Groovy / Java 17
I'm implementing a rabbitmq consumer for a simple demo project following the guidelines from micronaut project (...
0
votes
0
answers
23
views
How to I kick of tests written in Geb and Spock using SpockConfig.groovy file
How to I kick of tests written in Geb and Spock using SpockConfig.groovy file , currently we have test in mutiple classes and each class is kicked of to run the test , but I want to run all the tests ...
0
votes
0
answers
15
views
Spock fails a test, but doesn't give details and in summary says all tests passed
Bizzare behavior with grails spock test execution.
A test fails, but gives no info. It should have failed, so that's ok, but why am I getting no info and then get a Tests PASSED message?
grails> ...
0
votes
2
answers
260
views
How to mock OAuth2 token introspect using Spock
I have a spring-boot Webflux application and I am writing some tests using Spock and Groovy.
My Controllers are secured with OAuth opaque token which I need to mock a response from introspection.
My ...
0
votes
1
answer
23
views
What is the meaning of the output MonoJust for tests result in Spock
I have written some tests that in spock that give me results I can't make sense of. When I try to assert in the then: block the test fails with the output of MonoJust. I have no idea what that means. ...
0
votes
1
answer
229
views
Execution failed for task ':compileTestGroovy' when I try to run a groovy spock tests
I am getting an error when trying to run a groovy test with MockMvc
My test class looks like below:
@WebMvcTest
class BehavioralTest extends Specification{
@Autowired
MockMvc mvc;
// my test ...
1
vote
1
answer
140
views
Would it be possible to call a Kotlin function with named parameters from Groovy (including `copy`)?
Context - a Kotlin codebase with Spock/Groovy tests.
In my Groovy tests it would be convenient to call Kotlin functions with named parameters using the names. I use this particularly for test builders ...
0
votes
0
answers
32
views
Parsing through spock test results
All, I have a test suite developed using spock-groovy framework. The output of this is a set of html files. I have a requirement to run this test as part of a docker container on cloud. After the test ...
1
vote
0
answers
36
views
Spock invocation test print too few information
Is it possible to make Spock give more information about failed tests.
Below test example only print the name booServices.someFunc when too few invocation. But in this case I would like see the exact ...
1
vote
1
answer
58
views
Spock Test to Check that a Java Program has Indeed Extracted a Specific File Extension
I wrote the following program that successfully extracts a .json file. I want to check with Spock and Groovy that my method, indeed extracts a file with the .json extension. At the end of the question ...