Run Forked Tests in Grails on IntelliJ IDEA
How to resolve issues with Running Forked Tests in Grails on IntelliJ IDEA
When trying to run test-app on a Grails project in Intellij you may see a error similar to the following:
| Error Error running forked test-app: Could not load grails build listener class
java.lang.RuntimeException: Could not load grails build listener class
at org.codehaus.groovy.grails.cli.support.GrailsBuildEventListener.addGrailsBuildListener(GrailsBuildEventListener.java:258)
at org.codehaus.groovy.grails.cli.support.GrailsBuildEventListener.loadGrailsBuildListeners(GrailsBuildEventListener.java:106)
at org.codehaus.groovy.grails.cli.support.GrailsBuildEventListener.initialize(GrailsBuildEventListener.java:73)
at org.codehaus.groovy.grails.cli.fork.ForkedGrailsProjectClassExecutor.createEventListener(ForkedGrailsProjectClassExecutor.groovy:102)
at org.codehaus.groovy.grails.cli.fork.testing.ForkedGrailsTestRunner.createInstance(ForkedGrailsTestRunner.groovy:93)
at org.codehaus.groovy.grails.cli.fork.ForkedGrailsProjectClassExecutor.initializeProjectInstance(ForkedGrailsProjectClassExecutor.groovy:85)
at org.codehaus.groovy.grails.cli.fork.ForkedGrailsProjectClassExecutor.run(ForkedGrailsProjectClassExecutor.groovy:72)
at org.codehaus.groovy.grails.cli.fork.testing.ForkedGrailsTestRunner.main(ForkedGrailsTestRunner.groovy:75)
Caused by: java.lang.ClassNotFoundException: org.jetbrains.groovy.grails.rt.GrailsIdeaTestListener
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at groovy.lang.GroovyClassLoader.loadClass(GroovyClassLoader.java:648)
at groovy.lang.GroovyClassLoader.loadClass(GroovyClassLoader.java:758)
at groovy.lang.GroovyClassLoader.loadClass(GroovyClassLoader.java:746)
at org.codehaus.groovy.grails.cli.support.GrailsBuildEventListener.addGrailsBuildListener(GrailsBuildEventListener.java:255)
... 7 more
| Error Error running forked test-app: Could not load grails build listener class
Tests can execute in so-called forked mode. In this mode a separate JVM is started with an independent classpath from the Grails build system.
If you want to run tests in forked mode from within IntelliJ IDEA you'll get an error:
Error running forked test-app: Could not load grails build listener class (Use --stacktrace to see the full trace)
.
To make run tests in forked mode work with IntelliJ IDEA we must add the grails-rt.jar file to the lib folder of the project directory.
In a basic Windows 7 install you will find the file in a location similar to:
C:\Program Files (x86)\JetBrains\IntelliJ IDEA 13.0.2\plugins\Grails\lib
Add grails-rt.jar file to run forked tests in Intellij IDEA for Grails projects |
Now your Grails forked tests from within IntelliJ IDEA should run correctly.
Add the option
--debug-fork
to the Run Configuration to the test to help debug.
Another option: Disabled forked mode
Disable the forked mode for tests:
set
grails.project.fork.test = false
in grails-app/conf/BuildConfig.groovy
.
There is currently an open bug ticket for this issue:
Comments
Post a Comment