Adding Spock tests to Java project in Intellij

user1596371 picture user1596371 · Nov 21, 2013 · Viewed 14.3k times · Source

I have an existing Java project set up in Intellij 12 and am attempting to add some Groovy classes to it. I've started with attempting to add a simple Spock class for testing purposes, but when I right-click on the class it does not give me an option to run it.

I've taken a look at my Intellij configuration and it pulls in groovy correctly. Further, I can write a Groovy script that uses a Groovy class and that runs without problems so it appears that Groovy is wired in. Is there something else I need to configure to specifically run Spock tests?

Answer

Seagull picture Seagull · Nov 21, 2013

Easiest way to get spock and all dependencies is add library from maven.

Then, you should place your test in a folder, marked as test folder, if you want to allow batch processing of them.

If you place your script in folder, not marked as test, or source folder, you will be unable to run it.

If you can't see run button, it looks like Idea cannot recognise file as runnable, it isn't under source/test root, or it's extension is invalid.