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
0
votes
3 answers

JUnit and Spock test with maven-surefire-plugin

I have JUnit tests in src/test/java/ and groovy tests in src/test/groovy/. I can run every tests in IDE, but I want to add them to mvn test. If I use: org.apache.maven.plugins
damlit
  • 103
  • 1
  • 6
0
votes
1 answer

Spock Parametrized Specification doesn't work with CompileStatic

prerequisites: Adopt OpenJDK 11, Gradle 6.8.1, Groovy 3.0, Spock 2.0, Firstly I've got exceptions dependence with inner static builder class: #: [Static type checking] - Cannot find matching method java.lang.Object#withSomeMethod(int). Please check…
shkiper
  • 111
  • 4
0
votes
0 answers

Problem while authenticating URL in spock testing

I have a groovy file gitClone.groovy which has a function call. def call(credentials, url, project, branch, path, refs, noTags=false, timeout=20) { } I am writing a test for validating the 'url'. I want to write a test case which will validate…
Subhojoy Dey
  • 3
  • 1
  • 3
0
votes
1 answer

Using Spock/Groovy to test a Java method that extends HashMap - how to mock HashMap get method?

In our codebase, we use a specific class map which stores the results for authorization requests including whether or not someone has the auth to get in. Currently writing some unit tests (a thing I have little practice on) that contains this, a…
vidyadawg
  • 1
  • 1
0
votes
1 answer

Get the access to default java container (TestContainers) in spock test

I have a spock integration test which initiates additional container. @Shared protected GenericContainer seleniumStandalone = new GenericContainer<>("selenium/standalone-chrome:latest") .withExposedPorts(4444) …
maciejka
  • 818
  • 2
  • 17
  • 42
0
votes
1 answer

How do I parameterize Java methods and classes

I am using Spock for unit tests. I want to test Java methods and classes dynamically as in below example. Audit is a Java class. In addition, if possible, I would also like to make Audit class a parameter given: Audit audit = GroovyMock() …
Harish
  • 19
  • 2
0
votes
1 answer

Unable to resolve class JunitAdapter

I wrote a test where I am importing a class from package com/intel/epgsw/JunitAdapter.groovy When I try to run the test, I get this error: [ERROR] Failed to execute goal org.codehaus.gmavenplus:gmavenplus-plugin:1.5:testCompile (groovy) on project…
Subhojoy Dey
  • 3
  • 1
  • 3
0
votes
3 answers

How to test Spring JPA audit annotations?

I am having trouble testing the auditing annotations in Spring JPA (2.5.4) using an H2 in-memory database. I have a main class annotated with @EnableJpaAuditing, and a base class for my…
jaco0646
  • 15,303
  • 7
  • 59
  • 83
0
votes
2 answers

How to mock/spy Jenkins.insatance using spock

I have this code in my pipeline, now I want to add unit test for it using spock framework, the issue is how to mock or spy Jenkins.instance and all chaining methods. String deployPipeline = "Deploy/${projectID}/deploy-to-prod" def lastRelease =…
Reza
  • 18,865
  • 13
  • 88
  • 163
0
votes
1 answer

Failed to execute goal org.codehaus.gmavenplus:gmavenplus-plugin:1.6.1:generateStubs (groovy) : classpath InvocationTargetException: startup failed:

I am trying to compile using mvn verify but I am getting the error stated below: Failed to execute goal org.codehaus.gmavenplus:gmavenplus-plugin:1.6.1:generateStubs (groovy) on project jenkinsfile-test-shared-library: Error occurred while calling a…
Subhojoy Dey
  • 3
  • 1
  • 3
0
votes
1 answer

Java: Spock force to fail test on unrecorded mock invocation

I have java code and test written using groovy spock. Normally test follows this pattern My sample Java Code public User findUser(String id){ return userRepo.findById(id); } my sample test def "My Test"(){ given: String id = "sample" …
Viraj
  • 5,083
  • 6
  • 35
  • 76
0
votes
1 answer

spring boot & Spock

I have a springBootVersion = '2.3.2.RELEASE' app and I would like to use Spock for my unit and integration tests. I have this for Spock in my Gradle: testImplementation('org.springframework.boot:spring-boot-starter-test') { exclude…
sonoerin
  • 5,015
  • 23
  • 75
  • 132
0
votes
1 answer

Set env variable in spock

I want to set the env variable for fileDirName but not sure how to add In code: @Value("${file.dir.name}") private String fileDirName; Test case: def 'test file'() { when: def result = service.getFiles() then: result.success…
raaeusagvc
  • 71
  • 6
0
votes
1 answer

Maven-surefire is not running Spock tests annotated with @Tag

I'm trying to run only some of my Spock tests. To do so I use JUnit5 @Tag annotation. However, Spock tests with this annotation are not visible to maven-surefire whereas JUnit5 tests are. pom.xml
Jan Krakora
  • 2,500
  • 3
  • 25
  • 52
0
votes
1 answer

Conditional condition not working as expected

I noticed a weird behavior in how a condition in the then block gets evaluated. The condition should be evaluated after executing the when block, but in one specific case, it is getting executed before and so failing. I am able to reproduce the…
haridsv
  • 9,065
  • 4
  • 62
  • 65