Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Oct 16 10:42
    codecov[bot] commented #1386
  • Oct 16 10:40
    codecov[bot] commented #1386
  • Oct 16 10:39
    codecov[bot] commented #1386
  • Oct 16 10:38
    codecov[bot] commented #1386
  • Oct 16 10:38
    codecov[bot] commented #1386
  • Oct 16 10:38
    codecov[bot] commented #1386
  • Oct 16 10:38
    codecov[bot] commented #1386
  • Oct 16 10:37
    codecov[bot] commented #1386
  • Oct 16 10:37
    codecov[bot] commented #1386
  • Oct 16 10:34
    leonard84 assigned #1382
  • Oct 16 10:34
    leonard84 assigned #1386
  • Oct 16 10:34
    leonard84 review_requested #1386
  • Oct 16 10:33
    leonard84 opened #1386
  • Oct 15 14:21
    jan-krakora closed #1385
  • Oct 15 14:21
    jan-krakora commented #1385
  • Oct 15 12:52
    jan-krakora edited #1385
  • Oct 15 11:32
    jan-krakora edited #1385
  • Oct 15 11:31
    jan-krakora labeled #1385
  • Oct 15 11:31
    jan-krakora opened #1385
  • Oct 14 20:16
    leonard84 review_requested #1380
MAXIM GOLOTA
@golotamaxim
Hello everyone. I try to test my service class as subject with some collaborators. In my service class some method supposes to use Util class with static method. How can I mock this static method and provide different results for different test cases?
3 replies
stansvec
@stansvec:matrix.org
[m]
Anyone else experiences: java.lang.Exception: No runnable methods when running a spock test in the newest IDEA version 2021.2?
Alexander Kriegisch
@kriegaex
@stansvec:matrix.org, no. I think it would be helpful for you to be more specific.
stansvec
@stansvec:matrix.org
[m]

I upgraded IDEA to the newest version and then when I run any spock test (whole class or individual methods) I get this error in the test console:

java.lang.Exception: No runnable methods

    at org.junit.runners.BlockJUnit4ClassRunner.validateInstanceMethods(BlockJUnit4ClassRunner.java:191)
    at org.junit.runners.BlockJUnit4ClassRunner.collectInitializationErrors(BlockJUnit4ClassRunner.java:128)
    at org.junit.runners.ParentRunner.validate(ParentRunner.java:416)
    at org.junit.runners.ParentRunner.<init>(ParentRunner.java:84)
    at org.junit.runners.BlockJUnit4ClassRunner.<init>(BlockJUnit4ClassRunner.java:65)
    at org.junit.internal.builders.JUnit4Builder.runnerForClass(JUnit4Builder.java:10)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
    at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
    at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:33)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:50)
    at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
    at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:235)
    at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:54)

Was just wondering if this is somehow specific to my setup or a new general bug

Alexander Kriegisch
@kriegaex
When I said "be more specific", I was actually talking about an MCVE rather than a call stack without any code.
Alexander Kriegisch
@kriegaex
@stansvec:matrix.org: I just saw a similar problem in IDEA 2021.2 when running some tests in a Spock 2 project. Some tests run in IDEA, others do not. I cannot see a pattern yet. In Maven, all tests run,so it is an IDEA problem. What puzzles me is the JUnit 4 stuff in the stack trace. Spock 2 tests run on the JUnit 5 platform.
1 reply
Alexander Kriegisch
@kriegaex
I created https://youtrack.jetbrains.com/issue/IDEA-275517. Let us wait and see what the JetBrains people say.
Alexander Kriegisch
@kriegaex
BTW, I noticed so many bugs and breaking changes in 2021.2, I think it is the worst update in a long time. I think, I created 3 different IDEA issues in the last 24 hours alone.
stansvec
@stansvec:matrix.org
[m]
Thanks for taking care of this!
Hope it won't take too long for them to fix it
I've noticed declining stability/quality with every new IDEA release for a while and it's getting quite worrying
Also found more issues with the newest one (no spock related)..
Alexander Kriegisch
@kriegaex

I have a problem with this kind of test:

package de.scrum_master.stackoverflow

import de.jodamob.kotlin.testrunner.OpenedClasses
import de.jodamob.kotlin.testrunner.OpenedPackages
import de.jodamob.kotlin.testrunner.SpotlinTestRunner
import org.junit.runner.RunWith
import org.spockframework.util.VersionNumber
import spock.lang.IgnoreIf
import spock.lang.Specification
import spock.lang.Unroll

/**
 * See https://stackoverflow.com/q/48391716/1082681
 * See https://github.com/dpreussler/kotlin-testrunner
 */
@RunWith(SpotlinTestRunner)
@OpenedClasses(FinalClass)
//@OpenedPackages("de.scrum_master.stackoverflow")
@IgnoreIf({
  // de.jodamob.kotlin.testrunner.NoMoreFinalsClassLoader uses Javassist which tries to make
  // protected java.lang.ClassLoader.defineClass accessible. Due to JEP-396, this is forbidden since JDK 16.
  VersionNumber.parse(jvm.javaSpecificationVersion).major >= 16
})
class AnotherClassSpotlinRunnerTest extends Specification {
  def "use SpotlinRunner to stub final method in final class"() {
    given:
    FinalClass finalClass = Stub() {
      finalMethod() >> "mocked"
    }

    expect:
    new AnotherClass().doSomething(finalClass) == "mocked"
  }
}

The problem is that @IgnoreIf is evaluated too late for this case, because the error already occurs in the SpotlinTestRunner. I am looking for a way to keep this test in my Spock 1.3 playground project for reference, because up to JDK 15 is runs fine. Is there a way to stop a Spock (JUnit 4) test from running based on a condition, before the runner specified by @RunWith is excecuted?

Alexander Kriegisch
@kriegaex
Sorry, I made a copy & paste error with my previous post. Again:

I tried several things before, such as

Both are executed too late in the lifecycle, i.e. they are unable to prevent the SpotlinTestRunner from being initialised.

Actually, the runner has not been updated since version 0.3.1 in 2016, i.e. it knows nothing about JEP-396 and strong JDK encapsulation. The best solution would be for it to be upgraded by its author. My workaround for now is to replace the runner by a delegate, which I named JEP396AwareSpotlinTestRunner. It either passes through every method call to a SpotlinTestRunner or makes sure that all test executions are ignored in order to get correct test reporting.

package de.scrum_master.testing

import de.jodamob.kotlin.testrunner.SpotlinTestRunner
import org.junit.runner.Description
import org.junit.runner.manipulation.Filter
import org.junit.runner.manipulation.NoTestsRemainException
import org.junit.runner.manipulation.Sorter
import org.junit.runner.notification.RunNotifier
import org.junit.runners.model.InitializationError
import org.spockframework.runtime.Sputnik

class JEP396AwareSpotlinTestRunner extends Sputnik {
  private static final int javaMajor = Integer.parseInt(System.properties.getProperty("java.version").split("[.]")[0])
  public static final boolean hasJEP396 = javaMajor >= 16

  private static final Filter ignoreAllFilter = new Filter() {
    @Override
    boolean shouldRun(Description description) { return false }

    @Override
    String describe() { return "ignores all tests" }
  }

  private final Sputnik sputnik

  JEP396AwareSpotlinTestRunner(Class<?> clazz) throws InitializationError {
    super(clazz)
    sputnik = hasJEP396 ? this : new SpotlinTestRunner(clazz)
  }

  @Override
  void filter(Filter filter) throws NoTestsRemainException {
    if (hasJEP396)
      super.filter(ignoreAllFilter)
    else
      sputnik.filter(filter)
  }

  @Override
  void run(RunNotifier notifier) {
    if (hasJEP396)
      super.run(notifier)
    else
      sputnik.run(notifier)
  }

  @Override
  Description getDescription() {
    if (hasJEP396)
      return super.getDescription()
    else
      return sputnik.getDescription()
  }

  @Override
  void sort(Sorter sorter) {
    if (hasJEP396)
      super.sort(sorter)
    else
      sputnik.sort(sorter)
  }
}

The Spock spec still needs an @IgnoreIf or @Requires in addition to @RunWith(JEP396AwareSpotlinTestRunner), but otherwise no changes are required. It can even utilise a constant JEP396AwareSpotlinTestRunner.hasJEP396 for its own condition:

package de.scrum_master.stackoverflow

import de.jodamob.kotlin.testrunner.OpenedClasses
import de.jodamob.kotlin.testrunner.OpenedPackages
import de.scrum_master.testing.JEP396AwareSpotlinTestRunner
import org.junit.runner.RunWith
import spock.lang.IgnoreIf
import spock.lang.Specification

/**
 * See https://stackoverflow.com/q/48391716/1082681
 * See https://github.com/dpreussler/kotlin-testrunner
 */
@RunWith(JEP396AwareSpotlinTestRunner)
@IgnoreIf({ JEP396AwareSpotlinTestRunner.hasJEP396 })
@OpenedClasses(FinalClass)
//@OpenedPackages("de.scrum_master.stackoverflow")
class AnotherClassSpotlinRunnerTest extends Specification {
  def "use SpotlinRunner to stub final method in final class"() {
    given:
    FinalClass finalClass = Stub() {
      finalMethod() >> "mocked"
    }

    expect:
    new AnotherClass().doSomething(finalClass) == "mocked"
  }
}
Alexander Kriegisch
@kriegaex

See dpreussler/kotlin-testrunner#27.

Thanks all for listening to me talking to myself. But if I ask the community a question and find an answer, I think it is only fair to share it.

Peter Guo
@mushanzi1216
hello anyone knows how to mock a generic class
Alexander Kriegisch
@kriegaex
@mushanzi1216, please learn how to ask better questions, e.g. read this article. Then try again here, asking a question with enough detail to answer in a meaningful way.
What I mean is: Your question is not unlike "Does anyone know how to drive a car?" and then someone saying "yeah, sure". It would be the correct answer, but not helpful to the person asking.
treethingy
@treethingy
Hi, I'm looking for a sophisticated way to modify the way "Condition not satisfied:" output is rendered. I'm validating XML agains XSD and Schematron. I've created a hamcrest matcher and implemented "describeMismatch". Is there a better way to do it?
3 replies
liubo404
@liubo404
Error:Groovyc: While compiling tests of iceim: Could not instantiate global transform class org.spockframework.compiler.SpockTransform specified at jar:file:/home/ben/.m2/repository/org/spockframework/spock-core/2.0-groovy-3.0/spock-core-2.0-groovy-3.0.jar!/META-INF/services/org.codehaus.groovy.transform.ASTTransformation  because of exception java.lang.NullPointerException
how to resolve this error, any ideas, thanks a lot
I google for an hour, nothing useful can help~
the maven dependency below:
    <dependency>
            <groupId>org.spockframework</groupId>
            <artifactId>spock-core</artifactId>
            <version>2.0-groovy-3.0</version>
            <scope>test</scope>
        </dependency>

  <plugin>
                <groupId>org.codehaus.gmavenplus</groupId>
                <artifactId>gmavenplus-plugin</artifactId>
                <version>1.12.1</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>compile</goal>
                            <goal>compileTests</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.22.2</version>
                <configuration>
                    <useFile>false</useFile>
                    <includes>
                        <include>**/*Spec.java</include>
                    </includes>
                </configuration>
            </plugin>
陆龟
@xialugui
@liubo404 试试显示指定groovy版本
<!-- https://mvnrepository.com/artifact/org.codehaus.groovy/groovy-all -->
<dependency>
    <groupId>org.codehaus.groovy</groupId>
    <artifactId>groovy-all</artifactId>
    <version>3.0.8</version>
    <type>pom</type>
</dependency>
liubo404
@liubo404
image.png
@xialugui 好象还是不太行, 多谢~
Alexander Kriegisch
@kriegaex

@xialugui, groovy-all is not necessary for Spock 2.0.

@liubo404 , it is hard to reason about a partial POM without any code. Please be so kind as to share a reproducer on GitHub. This is called an MCVE. It helps us to understand and analyse your problem and you to get the answers you need.

liubo404
@liubo404
I think it's my problem, I used spock with spring-boot 2.4.4, that's why this error occurs.
thanks very much @kriegaex
I commit this to github issue, and close it.
spockframework/spock-example#44
├── pom.xml     //1.here inherit from spring-boot-starter-parent
├── README.md
└── spocky
    ├── pom.xml //2.spock depency 
    ├── spocky.iml
    └── src
        ├── main
        │   ├── java
        │   └── resources
        └── test
            ├── groovy
            │   └── com
            │       └── abc
            │           └── DemoSpec.groovy
            └── java
                └── DemoTest.java

//1.pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.4.4</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <groupId>com.abc</groupId>
    <artifactId>demo-parent</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>xxxx</name>
    <description>xxx</description>
    <packaging>pom</packaging>

    <modules>
        <module>spocky</module>
    </modules>
</project>


//2.spock depency pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>internal-control-parent</artifactId>
        <groupId>com.abc</groupId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>spocky</artifactId>

    <dependencies>
        <dependency>
            <groupId>org.spockframework</groupId>
            <artifactId>spock-core</artifactId>
            <version>2.0-groovy-3.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.spockframework</groupId>
            <artifactId>spock-spring</artifactId>
            <version>2.0-groovy-3.0</version>
            <scope>test</scope>
        </dependency>
   <!--
        with this or not, still the same ERROR:Groovyc....
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <version>2.5.0</version>
            <scope>test</scope>
        </dependency>

    --> 

    </dependencies>


    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.gmavenplus</groupId>
                <artifactId>gmavenplus-plugin</artifactId>
                <version>1.12.1</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>compile</goal>
                            <goal>compileTests</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.22.2</version>
                <configuration>
                    <useFile>false</useFile>
                    <includes>
                        <include>**/*Spec.java</include>
                    </includes>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>


//3.DemoSpec.groovy

package com.abc;

import spock.lang.Specification

class DemoSpec extends Specification {
    def "an integer can be incremented"() {
        given:
        int i = 1
        when:
        i++
        then:
        i == 2
    }
}
liubo404
@liubo404
finally, I change the spock-core version to 2.0-groovy-2.5, it's solve the problem
//2.spock depency pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>internal-control-parent</artifactId>
        <groupId>com.ctjsoft</groupId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>spocky</artifactId>

    <dependencies>
        <dependency>
            <groupId>org.spockframework</groupId>
            <artifactId>spock-core</artifactId>
            <version>2.0-groovy-2.5</version>
            <scope>test</scope>
        </dependency>
    </dependencies>


    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.gmavenplus</groupId>
                <artifactId>gmavenplus-plugin</artifactId>
                <version>1.12.1</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>compile</goal>
                            <goal>compileTests</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.22.2</version>
                <configuration>
                    <useFile>false</useFile>
                    <includes>
                        <include>**/*Spec.java</include>
                    </includes>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>
XIA YUN
@unxia
Hi, I'm looking for a way to inject spring bean into spock interceptor to prepare data , kind of like https://github.com/janbols/spock-dbunit, but using spring to do it
Alexander Kriegisch
@kriegaex
@liubo404, oh, you cross-posted from a Spock issue. In that case, a link would have suficed, no need to copy & paste everything here. Anyway, I am happy you solved your build configuration problem. Of course, you canot combine Groovy 3 with Spock for Groovy 2.5 or the other way around. You need to use the Groovy and Spock artifacts which match with each other. In your case, you chose to keep Groovy 2.5 and adjust Spock to it. The other way would have been to upgrade to Groovy 3.

@unxia, have you tried using Spock's Spring integration?
https://spockframework.org/spock/docs/2.0/all_in_one.html#_spring_module

If something is not working as expected there, it would make sense to publish an MCVE on GitHub in order to illustrate your problem. Writing one sentence, saying "I want to do A, similar to project B" does not quite precisely describe your problem.

liubo404
@liubo404
@kriegaex thanks, I'll try to upgrade to 3.0
陆龟
@xialugui
@liubo404 Spock的依赖很迷,即使你的版本是2.0-groovy-3.0,他的groovy版本也会是2.5。
Alexander Kriegisch
@kriegaex

@liubo404 Spock的依赖很迷,即使你的版本是2.0-groovy-3.0,他的groovy版本也会是2.5。

Like I said, this is not supposed to work and the Spock artifact should fit the Groovy version.

liubo404
@liubo404
@xialugui 多谢,刚开始学spock测试..版本确定很迷
force to use the 3.0 version
image.png
liubo404
@liubo404
I close this issue spockframework/spock-example#44
there @szpak recommented a elegant way to solve the version problem,
Overriding Dependency Versions with Spring Boot
Explicitly manage only the Groovy version via a property in maven
thanks
Juliane Hochstein
@exwima
Hi there, I'm new here. I'm trying to use the Spock Web Console at https://meetspock.appspot.com/ with the given example MyFirstSpec, but I'm getting an error message "Error interacting with the Spock Web Console server: error". Does anoyone know about this? I used the Spock Web Console at appspot sometimes during summer and it worked fine then.
Leonard Brünings
@leonard84
@exwima please try the new version https://gwc-experiment.appspot.com/
Juliane Hochstein
@exwima
@leonard84 That seems to work, thanks!
@leonard84 Is there an option to start with a Spock Test already given? And could you put the new URL into #1321 , too? That would be helpful.
Leonard Brünings
@leonard84
look at the section "sharing scripts", for how to provide prefilled data
Juliane Hochstein
@exwima
Ah, thanks!
Juliane Hochstein
@exwima
(My error, just pasted a Spock example in the Groovy Web Console and tried if it runs. The information about linking example scripts is right there if you read the page...)
I'm trying to give a short presentation about Spock in a course and wanted to refer to the web console if somebody wants to give it a first try. It's easier if there is already a short Spock test given, so I'll probably try to add an example for my fellow students. Thanks for the new URL!
Leonard Brünings
@leonard84
@exwima if you haven't seen it, there is also the Share as Linkbutton that will encode the current script into an url so that you can easily share it.
Juliane Hochstein
@exwima
Thanks again. :-)
emma.hi
@emma.hi:matrix.org
[m]
Hey, anyone know how to create unit test for service (grails 2.5.4)? I have tried to create TestServiceSpec and call some method in the service. Got this error --> No tests found in {packageName}.TestServiceSpec
Quinn
@qtpeters
Can anyone point me to where the versioning for the Spock Framework is explained? What does this actually mean: 1.2-groovy-2.4? Spock 1.2 FOR Groovy 2.4?
1 reply