How can I write a test for a plugin editing Groovy files?


I'm developing a plugin which converts JUnit test to Spock Tests. Therefore I am modifying Groovy files. This seems to be a problem for my test.

I'm having the following test case

class ConvertJavaToGroovyTest : LightJavaCodeInsightFixtureTestCase() {

override fun getTestDataPath() = "src/test/resources/testdata"

fun testConversion() {
val psiFile = myFixture.configureByFile("BookTest.groovy") as GroovyFile
testAction(ConvertJavaToGroovy(), psiFile)

/** inspired by myFixture.testAction */
private fun testAction(action: AnAction, psiFile: PsiFile): Presentation? {
val event = TestActionEvent(action)
if (event.presentation.isEnabled && event.presentation.isVisible) {
JUnitToSpockApplier(event, psiFile).transformToSpock()
return event.presentation

And I'm getting the following error:

class com.intellij.psi.impl.source.PsiPlainTextFileImpl cannot be cast to class org.jetbrains.plugins.groovy.lang.psi.GroovyFile (com.intellij.psi.impl.source.PsiPlainTextFileImpl and org.jetbrains.plugins.groovy.lang.psi.GroovyFile are in unnamed module of loader 'app')

The file is found, but is considered to be plain text as the Groovy file type is unknown. I think I have to activate the Groovy extension, but I don't know how to do that correctly.

I tried to copy some Groovy test files from the Community Edition to inherit from LightGroovyTestCase.

This results in the following error:

java.lang.RuntimeException: Cannot find IntelliJ IDEA project files at /home/mhofmannsobik/.gradle/caches/modules-2/files-2.1/com.jetbrains.intellij.idea/ideaIC/2019.3.3/4c54deba9ff34a615b3072cd2def3558ff462987/ideaIC-2019.3.3

at com.intellij.testFramework.LightPlatformTestCase.initProject(
at com.intellij.testFramework.LightPlatformTestCase.doSetup(
at com.intellij.testFramework.fixtures.impl.LightIdeaTestFixtureImpl.setUp(
at com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl.setUp(
at com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase.setUp(
at org.jetbrains.plugins.groovy.LightGroovyTestCase.setUp(LightGroovyTestCase.kt:20)
Comment actions Permalink
Official comment

Hi Martin Hofmannsobik

Chris Campbell is right, this is the same problem. 
Groovy plugin depends on properties plugin, to make the test load the Groovy plugin please include "properties":

setPlugins("Groovy", "java", "properties") // Bundled plugin dependencies


Comment actions Permalink


It looks like you need to add the Groovy plugin to your dependencies. You should declare it both in Gradle build file and plugin.xml.

Please check the documentation regarding the Plugin Dependencies.



plugins 'Groovy', ...


Comment actions Permalink

Hi Jakub,

Groovy plugin is already defined:


intellij {

setPlugins("Groovy", "java") // Bundled plugin dependencies



My production code works fine, it's just a problem of the test.

If I missed relevant, here's complete the project code:

Comment actions Permalink

Hi Martin,


Not sure but this sounds exactly like a problem I just faced. Basically, for testing you need to explicitly include all plugins that you depend on - even transitive ones - even if your set up works in production. Details here

For example, to depend on the JavaScript plugin this means also depending on "CSS" plugin. You'd have to figure out what other plugins the groovy plugin depends on and add that to the list.



Comment actions Permalink

Hi Chris, hi Daniil Ovchinnikov,

the transitive dependency did solve the problem. The Groovy file is now recognized. Thank you very much.




Please sign in to leave a comment.