Android Studio 3 does not run tests in Spock
Asked Answered
S

1

7

I updated Android Studio to version 3 and since then all my spock tests, when in a java module, do not run when trying to run them from inside the application (right click on groovy folder -> Run 'Tests in groovy'). I get a:

Class not found: "package.name.classname"Empty test suite."

Same if I try to run a single test.

If I run the test task from the gradle panel I get this: error. Cause: unknown.


On the other hand:

  • Any spock tests in android modules run fine.
  • All my java tests in all my modules run fine.
  • All my tests (spock and java) run fine when running them from outside AS using gradle (gradlew clean test).

My setup:


A few things I tried after searching in both google and here:

  • changing the android gradle plugin back to v2.3.3 and gradle to v3.3
  • trying to copy all groovy classes to build/classes/java/test
Secession answered 26/10, 2017 at 13:31 Comment(7)
Just to clarify, do you have your spock tests in src/test/groovy or src/test/java?Millenarian
In src/test/groovy.Secession
I found this issue in google issue tracker which contains a temporary workaround. I tried it and it works on me too resulting in the same problem that the reporter has: class already exists.Secession
@le0nidas, I suggest you star the issue to mark that you are affected by itInfection
I didn't know i could do that. thank you.Secession
@Secession try this fix instead, which workaround the problem while avoiding the "class already exists" problem. Try to add this to build.gradle sourceSets { test { groovy { // Workaround for issue issuetracker.google.com/issues/65712492 // regarding to "Class not found .... Empty test suite" issue outputDir = sourceSets.test.java.outputDir } } } And yes, the last comment in that thread is me.Katekatee
@thinkpanda That worked find. Thank youSecession
D
3

So this is more of a workaround than an actual solution but it should give you your debugger back which is probably 90% of the value anyway:

You can run your test suite like:

./gradlew <module>:test --debug-jvm

And the jvm running your tests will suspend until a debugger attaches.

From Android Studio bring up the action chooser by pressing ctrl + shift + a (on linux anyway, check the equivalent for your OS) and select:

Attach to local process...

Once Android Studio attaches the tests will begin running.

The --debug-jvm flag can be used together with --tests to debug an individual test:

./gradlew <module>:test --tests fully.qualified.test.Test --debug-jvm
Didactics answered 14/11, 2017 at 3:1 Comment(1)
cmd + shift + a on a macFatality

© 2022 - 2024 — McMap. All rights reserved.