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

Running single test in IntelliJ Idea 2021.2.3 (Ultimate edition) sometimes not offered

I have the Java project (Maven/Spring/Spock). It appears that I couldn't run single test in test suite (class) randomly. In some test classes it possible, in some other its not - entire test suite is the only available choice. This is annoying while…
Tomáš Mika
  • 210
  • 1
  • 13
0
votes
1 answer

Groovy Spock: How do you pass in new Exception into when method without throwing error right away

I am trying to test a kafka error handler that takes in an Exception but as soon as I declare it in spock it actually throws it. def 'test example'() { when: service.emitError(new Exception('test exception')) then: // do some…
0
votes
0 answers

Spock: manage specification execution order

Disclaimer: I do understand that the tests should be isolated and the order should not matter. And in most of cases it really doesn't matter. Please see below the explanation of the case. Some tests should be executed under the same user, but with…
Bohdan Nesteruk
  • 794
  • 17
  • 42
0
votes
1 answer

Geb - Doesn't work attr. required (groovy test)

I create tests (groovy, geb). I have something like this : class test extends Module { static content = { first{ $("input", id: "one") } second(required: false) { $("input", id: "two") } third(required: false) { $("input", id: "three")…
0
votes
1 answer

Mocking Map parameter in Spock Framework Java test

I am having difficulty in getting a test to work using Spock Framework in a Java project. I have the following: - Person.class - Attribute.class I have a service class which is being mocked in my test. The method I am trying to mock has the…
pillow
  • 39
  • 6
0
votes
1 answer

Executing js.exec in GebSpock ends with "java.lang.IllegalArgumentException: The last argument to the js function must be string-like"

I have the following lines in the page object class (to deal with Shadow DOM): 11 headerContent(wait:true) { $("content-header") } 12 shadowRoot0(wait:true) { js.exec("return arguments[0].shadowRoot", headerContent) } However, when…
0
votes
1 answer

Groovy Spock How to mock static functions from java classes

I want to mock function like Files.copy(), LocalDate.now() from Java e.g. In one of my function I have public int functionForTest(){ var now = LocalDate.now() if(now.getMonth() == 2) return 55; if(now.getMonth() == 4) …
Mateusz Sobczak
  • 1,551
  • 8
  • 33
  • 67
0
votes
0 answers

How to run Spock unit tests without intializing Grails environment

I have a Spock unit test in a Grails app. In IntelliJ IDEa I can either run it with grails environment and then it means I wait a minute until the environment loads to run the test even though I do not need the environment. The other option is to…
Ev0oD
  • 1,395
  • 16
  • 33
0
votes
1 answer

Unable to mock local objects in method using Spock

I'm unable to mock the below local objects - env, service, creds. These are classes from imported cloud foundry dependencies. How do I write a test case covering all conditions for below Groovy code using Spock or Junit 4 without refactoring the…
Vaishnavi Killekar
  • 457
  • 1
  • 8
  • 22
0
votes
0 answers

How to return dummy Job or Run in Jenkins Pipeline Spock Test?

I have a method to check if a Jenkins job's next build exists or not within 10 attempts. void checkNextBuild10Attempts() { int attempt = 0 while (attempt < 10) { Job job = JenkinsUtils.getJob(jobName) Run nextBuild =…
avu
  • 1
  • 1
0
votes
1 answer

Spock tests failing with org.junit.runners.model.InvalidTestClassError:

After upgrading to spock-core 2.0 , my tests are failing with below error: org.junit.runners.model.InvalidTestClassError: Invalid test class 'com.spock.test.TestSpockSpecification': 1. No runnable methods at…
0
votes
1 answer

Java testing issue with argument seen as array although it is long

I have a test: def "should get product by id"() { given: Product product = getBeer(UPLOADED_FILE_DETAILS_IMG) productRepository.getByIdOrThrow(product.id().get()) >> product then: …
0
votes
1 answer

How to test Java class with Spock?

I am trying to test a class in Java with spock. I am very new to it. public class VerifyUser { private final ServiceFacade serviceFacade; //here is constructor @RequestMapping(name = "verifyUser", path = "/verifyuser", …
user9347049
  • 1,927
  • 3
  • 27
  • 66
0
votes
0 answers

Mocking Jenkins internal functions with Spock and jenkins-spock

What I'm trying to do is create a method mock that returns a mock so I can test the folloging disconnectNode method of a class. What I'm trying to mock is the getNode and toComputer calls in the getJenkinsNode method. Computer getJenkinsNode(String…
0
votes
1 answer

Getting NullPointerException when trying to unit test kafka publisher controller

I am trying to test a controller that publishes in Kafka topic but my unit test keeps falling because I am getting null for kafkaTemplate.send(). Controller class public class Controller { private final KafkaTemplate
Medu
  • 1
  • 2
1 2 3
99
100