Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Aug 09 13:37
    leonard84 milestoned #1503
  • Aug 09 13:37
    leonard84 assigned #1503
  • Aug 08 12:27
    leonard84 closed #1505
  • Aug 08 08:17
    ArkiMargust commented #1505
  • Aug 05 16:25
    sdoeringNew commented #1506
  • Aug 05 16:20
    sdoeringNew commented #1506
  • Aug 05 13:04
    leonard84 commented #1506
  • Aug 05 10:27
    sdoeringNew opened #1506
  • Aug 05 10:27
    sdoeringNew labeled #1506
  • Aug 05 07:27
    leonard84 commented #1505
  • Aug 04 19:26
    konradczajka synchronize #1503
  • Aug 04 17:09
    ArkiMargust commented #1505
  • Aug 04 15:57
    leonard84 commented #1505
  • Aug 04 15:30
    ArkiMargust opened #1505
  • Aug 04 15:30
    ArkiMargust labeled #1505
  • Aug 03 17:23
    konradczajka synchronize #1503
  • Aug 01 10:13
    tangjiafu commented #1504
  • Aug 01 10:13
    leonard84 closed #1504
  • Jul 31 02:00
    tangjiafu commented #1504
  • Jul 31 02:00
    tangjiafu commented #1504
Sidney Coelho
@sidneydemoraes

Hello everyone. I have a problem similar to RealForce1024 but I already have the Jupiter dependency corretly setup. I'm trying to create a Spec but TestEngine with ID 'spock' failed to discover tests.
Can anyone give me some light on this?

I'm using IntelliJ and this is my build.gradle file:

plugins {
    id 'java'
}

group 'org.example'
version '1.0-SNAPSHOT'

repositories {
    mavenCentral()
}

dependencies {
    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'

    implementation 'org.codehaus.groovy:groovy:3.0.10'
    testImplementation platform("org.spockframework:spock-bom:2.1-groovy-3.0")
    testImplementation "org.spockframework:spock-core"
    testRuntimeOnly 'net.bytebuddy:byte-buddy:1.12.8'
}

test {
    useJUnitPlatform()
}
Sidney Coelho
@sidneydemoraes
Tried the official documentation but it doesnt help much actually.
Sidney Coelho
@sidneydemoraes
Just found the root cause. It was related to Gradle, not Spock. It was missing the Groovy plugin. There is no mention at all to that on the documentation.
Mark Logs
@mark-logs-code-hub
Hi,guys. I have mutiple spock test. I wanna composite it. and this spock test have order. How to do that ?
1 reply
sorry , I'm not English native speaker.
Søren Markert
@sorenmarkert
Hey everyone. I've encountered a problem, that the cleanup() method does not get executed. The setup() method does get called, and so does cleanupSpec().
Using: spock-core-2.1-groovy-2.5 and groovy-all-1.3-2.5.12.jar
I've tried both with and without a where: block.
Am I missing something? Or is this a bug?
10 replies
sunny_me
@sunny_me:matrix.org
[m]

Hello team 😃
I am facing below problem while writing test using SPOCK
I would like to know what knowledge gap I have, to understand why its not working

I have a main class called ClassUnderTest

@AllArgsConstructor
class ClassUnderTest {

    MyCache cache;

    def doSomething(String key, String value){
        cache.add(key, value);
    }

}

A Facade spec called MyFacade.

class MyFacade extends Specification{

    MyCache cache = new MyCache()

    def ClassUnderTest getInstance(){
        return new ClassUnderTest(cache, Mock(OtherDependency))
    }

    def boolean isPresentInCache(String someKey){
        return null != cache.get(someKey)
    }
}

and test spec called ClassUnderTestSpec.


class ClassUnderTestSpec extends Specification{

    MyFacade facade = new MyFacade()

    def 'check if key is added to cache'(){
    given:'get the instance from facade'
    ClassUnderTest instance = facade.getInstance()

    when: ' we call do something'
    instance.doSomething('myKey', 'myValue')

    then: 'cache should have myKey'
    facade.isPresentInCache('myKey')
    }
}

my main goal is to test if ClassUnderTest is populating the cache correctly.
To abstract it out I am using facade. So that my test remains unchanged if the cache class changes say from MyCache to any other class.

So in test I want

  1. get the instance
  2. pass the key and value to ClassUnderTest
  3. check if ClassUnderTest populates the cache using isPresentInCache

Somehow even though facade has cache instance and same MyCache instance is injected in ClassUnderTest, the test doesn't pass 😐️

Thanks for your time and help in advance. 😅
PS: I am a Java developer. Know Groovy only just by writing SPOCK tests

1 reply
Alessandro Morsiani
@Alessandro1985
Hi All, I have an issue integrating spock in my spring boot app:
Could not instantiate global transform class org.spockframework.compiler.SpockTransform specified at jar:file:/C:/Users/alessandro.morsiani/.m2/repository/org/spockframework/spock-core/2.1-groovy-3.0/spock-core-2.1-groovy-3.0.jar!/META-INF/services/org.codehaus.groovy.transform.ASTTransformation because of exception java.lang.NullPointerException: Cannot invoke "java.net.URL.toString()" because the return value of "java.security.CodeSource.getLocation()" is null
I have used different versions of spock and the issue persists..could you tell me please a stable groovy-spock dependencies?
Leonard Brünings
@leonard84
@Alessandro1985 that error only occurs when the Groovy version does not match the Spock version.
Alessandro Morsiani
@Alessandro1985
@leonard84 thanks for your reply! - so if I use the latest groovy https://mvnrepository.com/artifact/org.codehaus.groovy/groovy/3.0.11 which version of spock core (https://mvnrepository.com/artifact/org.spockframework/spock-core) should I use?
Leonard Brünings
@leonard84
spock-core-2.1-groovy-3.0 would be correct, I would assume that you get another version for some reason, you can try to run with -Dspock.iKnowWhatImDoing.disableGroovyVersionCheck=true and look at the logged error message.
Alessandro Morsiani
@Alessandro1985
Thanks @leonard84
Leonard Brünings
@leonard84
did you find the problem?
Alessandro Morsiani
@Alessandro1985
@leonard84 I still trying to understand where is the issue. mvn -Dspock.iKnowWhatImDoing.disableGroovyVersionCheck=true has this error: Unknown lifecycle phase ".iKnowWhatImDoing.disableGroovyVersionCheck=true". You must specify a valid lifecycle phase or a goal in the format <plugin-prefix>:<goal> or <plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]
:<goal>. Available lifecycle phases are: validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources,
process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy, pre-clean, clean, post-clean, pre-site, site, post-
site, site-deploy.
It doesn't tell me if I have versions mismatches
Leonard Brünings
@leonard84
that is just a system property not a maven goal, you still need to call test or test-compile
and it looks like you shell requires that you need to put it in quotes, e.g. mvn "-Dspock.iKnowWhatImDoing.disableGroovyVersionCheck=true" test
Alessandro Morsiani
@Alessandro1985
Ok now the build is success using mvn "-Dspock.iKnowWhatImDoing.disableGroovyVersionCheck=true" test with no issues about dependencies. If I run a basic spock test then it fails with the same error: Could not instantiate global transform class org.spockframework.compiler.SpockTransform specified at jar:file:/C:/Users/alessandro.morsiani/.m2/repository/org/spockframework/spock-core/2.1-groovy-3.0/spock-core-2.1-groovy-3.0.jar!/META-INF/services/org.codehaus.groovy.transform.ASTTransformation because of exception java.lang.NullPointerException: Cannot invoke "java.net.URL.toString()" because the return value of "java.security.CodeSource.getLocation()" is null
Leonard Brünings
@leonard84
please run mvn dependency:tree and look for groovy/spock versions
Alexander Kriegisch
@kriegaex
Damn, I wanted to edit, not delete
Leonard Brünings
@leonard84
@kriegaex the tolerant version is not yet released
Alexander Kriegisch
@kriegaex
Again: I am reminded of https://stackoverflow.com/q/72515326/1082681. @leonard84 already made the code I mentioned more fault-tolerant.
Yes, I know.
Which gives you and @Alessandro1985 the chance to find the root cause.
Oh, it is the same Alessandro asking here as on SO, I just noticed.
Leonard Brünings
@leonard84
and only if it failed
@Alessandro1985 you could try the current snapshot 2.2-groovy-3.0-SNAPSHOT from https://oss.sonatype.org/content/repositories/snapshots/org/spockframework/
Alexander Kriegisch
@kriegaex
Then it is pretty much clear, OK. Must be something is Alessandro's build config. Gonna leave you guys up to it, I am off to making dinner. 🙂
Alessandro Morsiani
@Alessandro1985
Thanks @leonard84 and @kriegaex for your help. So from the dependency:tree I have:
FO] +- org.codehaus.groovy:groovy:jar:3.0.1:compile
[INFO] +- org.spockframework:spock-core:jar:2.1-groovy-3.0:test
[INFO] | - org.junit.platform:junit-platform-engine:jar:1.8.2:test
[INFO] +- org.spockframework:spock-spring:jar:2.1-groovy-3.0:test
[INFO] +- org.spockframework:spock-junit4:jar:2.1-groovy-3.0:test
[INFO] +- org.codehaus.mojo.groovy:groovy-mojo-support:jar:1.0-beta-3:compile
[INFO] | +- org.codehaus.mojo.groovy.runtime:groovy-runtime-api:jar:1.0-beta-3:compile
[INFO] | | - org.codehaus.mojo.groovy.feature:groovy-feature-api:jar:1.0-beta-3:compile
[INFO] | +- org.codehaus.mojo.groovy.runtime:groovy-runtime-default:jar:1.0-beta-3:compile
[INFO] | | - org.codehaus.mojo.groovy.runtime:groovy-runtime-1.1:jar:1.0-beta-3:compile
[INFO] | | +- org.codehaus.mojo.groovy.feature:groovy-feature-support:jar:1.0-beta-3:compile
[INFO] | | +- org.codehaus.mojo.groovy.runtime:groovy-runtime-support:jar:1.0-beta-3:compile
[INFO] | | +- org.codehaus.groovy:groovy-all-minimal:jar:1.1-rc-3:compile
[INFO] | | +- org.codehaus.mojo.groovy.support:ant-1.7.0:jar:1.0-beta-3:compile
[INFO] | | | - org.apache.ant:ant-launcher:jar:1.7.0:runtime
[INFO] | | +- com.thoughtworks.qdox:qdox:jar:1.6.3:compile
[INFO] | | - jline:jline:jar:0.9.91:compile
[INFO] | +- org.codehaus.mojo.groovy:groovy-mojo-common:jar:1.0-beta-3:compile
4 replies
Leonard Brünings
@leonard84
This looks suspicious org.codehaus.groovy:groovy-all-minimal:jar:1.1-rc-3
Try removing/excluding org.codehaus.mojo.groovy:groovy-mojo-support:jar:1.0-beta-3
Alessandro Morsiani
@Alessandro1985
@leonard84 same result
and <dependency>
<groupId>org.spockframework</groupId>
<artifactId>spock-core</artifactId>
<version>2.2-groovy-3.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.spockframework</groupId>
<artifactId>spock-spring</artifactId>
<version>2.2-groovy-3.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.spockframework</groupId>
<artifactId>spock-junit4</artifactId>
<version>2.2-groovy-3.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>
results as: Cannot resolve org.spockframework:spock-spring:2.2-groovy-3.0-SNAPSHOT
Leonard Brünings
@leonard84
You need to add https://oss.sonatype.org/content/repositories/snapshots/ as an additional repository
Alessandro Morsiani
@Alessandro1985
Hey @leonard84 - hope you are well and you had a godd weekend!! So my from the build I have:
Groovyc: While compiling [tests of global-tournaments-api-server]: Could not instantiate global transform class org.spockframework.compiler.SpockTransform specified at jar:file:/C:/Users/alessandro.morsiani/.m2/repository/org/spockframework/spock-core/2.2-groovy-3.0-SNAPSHOT/spock-core-2.2-groovy-3.0-20220708.133358-51.jar!/META-INF/services/org.codehaus.groovy.transform.ASTTransformation because of exception org.spockframework.util.IncompatibleGroovyVersionException: The Spock compiler plugin cannot execute because Spock 2.2.0-groovy-3.0-SNAPSHOT is not compatible with Groovy 2.5.14. For more information (including enforce mode), see https://docs.spockframework.org (section 'Known Issues').
Spock artifact: unavailable
Groovy artifact: unavailable
18 replies
but from my dependency tree I have groovy 3.0.1 loaded:
[INFO] +- org.codehaus.groovy:groovy:jar:3.0.1:compile
[INFO] +- org.codehaus.groovy:groovy-all:pom:3.0.1:compile
[INFO] | +- org.codehaus.groovy:groovy-ant:jar:3.0.1:compile
[INFO] | | +- org.apache.ant:ant:jar:1.10.7:compile
[INFO] | | +- org.apache.ant:ant-junit:jar:1.10.7:runtime
[INFO] | | +- org.apache.ant:ant-launcher:jar:1.10.7:compile
[INFO] | | - org.apache.ant:ant-antlr:jar:1.10.7:runtime
[INFO] | +- org.codehaus.groovy:groovy-cli-picocli:jar:3.0.1:compile
[INFO] | +- org.codehaus.groovy:groovy-console:jar:3.0.1:compile
[INFO] | +- org.codehaus.groovy:groovy-datetime:jar:3.0.1:compile
[INFO] | +- org.codehaus.groovy:groovy-docgenerator:jar:3.0.1:compile
[INFO] | | - com.thoughtworks.qdox:qdox:jar:1.12.1:runtime
[INFO] | +- org.codehaus.groovy:groovy-groovydoc:jar:3.0.1:compile
[INFO] | | - com.github.javaparser:javaparser-core:jar:3.15.11:compile
[INFO] | +- org.codehaus.groovy:groovy-groovysh:jar:3.0.1:compile
[INFO] | | - jline:jline:jar:2.14.6:compile
[INFO] | +- org.codehaus.groovy:groovy-jmx:jar:3.0.1:compile
[INFO] | +- org.codehaus.groovy:groovy-json:jar:3.0.1:compile
Alexander Kriegisch
@kriegaex
This message was deleted
image.png
image.png
Jason-Terry
@Jason-Terry
Hey folks
Alexander Kriegisch
@kriegaex
Hello Jason. Do you have an actual question, or did you just want to say hi? 😉
SimonBarnatt
@SimonBarnatt

Hey,

Does anyone know how you call a Spock test from another Groovy class and return the result?

Cheers

3 replies
Łukasz
@nluk

Hi, I've observed strange behavior when working with static fields in Spock.
The initialization order is different than I'd get with ~similiar example in java. Minimal example is as follows (not idiomatic groovy, but that's not the point):

    class Foo {
        public static List<Object> getList(){
            print("Getting list")
            return new ArrayList<>();
        }
    }

    class MySpec extends Specification {
        static {
            print("Static block")
        }

        static List<Object> = Foo.getList()


        def "test"(){
            expect:
                1 == 1
        }
    }

I would expect the order of messages to be:

  1. Static block
  2. Getting list

But it's totally the other way. Is it something groovy-specific, or some spock lifecycle magic? It works as expected in java. Could you please give me some explanation, or point me to related docs.

8 replies