I recently had this problem: I was writing some tests with Spock, but IntelliJ IDEA wouldn’t run them. It would run my JUnit tests (written with JUnit 4), but it wouldn’t run my Spock tests (or “specs”, if you prefer). At least this is how it seemed to me. I had made this work before, so I couldn’t understand at all why it didn’t work now. And, of course, I wanted to get this working for a training course, so I felt a certain pressure to get it to work. Nothing made sense to me.

Symptoms

In IDEA, I tried to run all the tests from my src/test source folder. Spock tests did not run.

I tried to run all the tests from just the src/test/groovy source folder. Spock tests did not run.

I tried to run all the tests from just the src/test/java source folder. JUnit 4 tests ran as expected.

I tried to rebuild the project. No change.

I tried Invalidate Caches and Restart. No change.

I tried to run all these tests from Gradle, in order to isolate the problem to some IDEA configuration setting, but even with Gradle I saw the same behavior. I couldn’t run Spock tests. I looked inside build/ and saw that Gradle had built my Groovy source code, but still, Spock tests did not run. It look to me as though Gradle weren’t even trying. This seemed really strange to me, since I had created this Java project exactly the same way as I’d done in the past.

The Mistake

Summary

TIL what happens when I forget to “extend Specification” when writing Spock specs: #gradle silently doesn’t run any tests. Sadly, it looks like a build task failure when it isn’t. I wonder how I could get the feedback, “I ran the tests, but there weren’t any.”