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
ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
le0nidas
  • 79
  • 3
  • Just to clarify, do you have your spock tests in `src/test/groovy` or `src/test/java`? – Leonard Brünings Oct 27 '17 at 07:39
  • In `src/test/groovy`. – le0nidas Oct 27 '17 at 07:48
  • 1
    I found [this issue](https://issuetracker.google.com/issues/65712492) 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*. – le0nidas Oct 27 '17 at 08:00
  • @le0nidas, I suggest you star the issue to mark that you are affected by it – Love Oct 28 '17 at 13:07
  • I didn't know i could do that. thank you. – le0nidas Oct 29 '17 at 11:40
  • @le0nidas 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 https://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. – Herman Cheung Feb 04 '18 at 16:59
  • @thinkpanda That worked find. Thank you – le0nidas Feb 08 '18 at 12:05

1 Answers1

2

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
QuirijnGB
  • 811
  • 1
  • 9
  • 18
Troy Patrick
  • 190
  • 2
  • 12