0

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 org.junit.runners.ParentRunner.validate(ParentRunner.java:525)
    at org.junit.runners.ParentRunner.<init>(ParentRunner.java:102)
    at org.junit.runners.BlockJUnit4ClassRunner.<init>(BlockJUnit4ClassRunner.java:84)
    at org.junit.runners.JUnit4.<init>(JUnit4.java:23)
    at org.junit.internal.builders.JUnit4Builder.runnerForClass(JUnit4Builder.java:10)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:70)
    at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:37)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:70)
    at org.junit.runners.model.RunnerBuilder.runners(RunnerBuilder.java:125)
    at org.junit.runners.model.RunnerBuilder.runners(RunnerBuilder.java:111)

I am using below configuration in my build.gradle file :

testImplementation platform("org.spockframework:spock-bom:2.0-M5-groovy-3.0") //copied from spock example
testImplementation "org.spockframework:spock-core:2.0-M5-groovy-3.0"
implementation localGroovy() //3.0.7 as I am using gradle 7

I am running these test with junit 4 ,Can someone please help

tim_yates
  • 167,322
  • 27
  • 342
  • 338

1 Answers1

3

Spock 2.0 builds on top of JUnit 5 and does not work with legacy JUnit 4. Also, it has been out for some time now, and there are no reasons to use milestones.

See this for a full example. Pay attention to the useJUnitPlatform part. E.g.:

dependencies {
  testImplementation platform("org.codehaus.groovy:groovy-all:3.0.9")
  testImplementation platform("org.spockframework:spock-bom:2.0-groovy-3.0")
  testImplementation "org.spockframework:spock-core"

  testRuntimeOnly "net.bytebuddy:byte-buddy:1.11.18" // allows mocking of classes (in addition to interfaces)
  testRuntimeOnly "org.objenesis:objenesis:3.2"      // allows mocking of classes without default constructor (together with ByteBuddy or CGLIB)
}

test {
  useJUnitPlatform()
}
Bjørn Vester
  • 6,851
  • 1
  • 20
  • 20
  • Hi I have tried using useJUnitPlatform() but it didn't execute any test cases when I use it. I used it as below for my integrationtest . integrationtest { useJUnitPlatform() } Other than that I have also tried to includeEngines("spock") and included platform-runner dependency but none of the options work for me . – user14446456 Sep 23 '21 at 16:12
  • @user14446456 Did you try running the `spock-example` project? – Leonard Brünings Sep 23 '21 at 17:28
  • Yes I tried that and I am able to run it successfully. – user14446456 Sep 24 '21 at 05:01
  • @user14446456, then the problem is in your project configuration. Please post a full [MCVE](https://stackoverflow.com/help/mcve), ideally on GitHub, in order to make the problem reproducible. Then you probably get a correct answer quickly. – kriegaex Sep 24 '21 at 14:37
  • @user14446456 were you able to figure this out? – theprogrammer Apr 18 '22 at 14:44