Skip to main content

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

How to find the grails-rt.jar file to fix forked tests in Intellij IDEA using Grails projects
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:

http://youtrack.jetbrains.com/issue/IDEA-61453







Software Development Blogs - BlogCatalog Blog Directory

Popular posts from this blog

Change Port on a Spring Boot Application when using intelliJ

Change Port on a Spring Boot Application when using intelliJ  Two ways to change the port that the embedded Tomcat is using in a Spring Boot Application. The first way is to modify the application properties in the resources folder: Update application props in Spring Boot Application There are a couple issues with this approach.  You might only want this port change in your local environment and if you check it in by accident you might break things. Alternatively, you can use a command line parameter. Go to Run -> Edit Configurations -> VM options Then enter in the following argument: -Dserver.port=8090 Then click apply and OK and attempt to run the application again. Update port using VM option

How to set up a SQL Server 2008 Local Database

Setting up and Configuring your Microsoft SQL Server 2008 Local Database Download SQL Server Download SQL Server Express.  Express is the Free edition of MS SQL Server http://www.microsoft.com/en-us/download/details.aspx?id=1695 Install your SQL Server Instance Click the Start button -> Click Microsoft SQL Server 2008 -> Click Configuration Tools -> Select SQL Server Installation Center Select Installation -> Select New SQL Server stand-alone installation Select SQL Server stand-alone installation Get your Local SQL Server Service Up and Running Open up the SQL Server Configuration Manager Click the Start button -> Click Microsoft SQL Server 2008 -> Click Configuration Tools -> Select SQL Server Configuration Manager Setup SQL Server Config Manager Start up the SQL Services You want to ensure the following services are in the "Running" State and then you want to set the following services to automatic St...

Building Microservices with JHipster

Check out this article on Medium and LinkedIn Pulse, for a brief overview of microservices as a primer for working with JHipster to build web applications with a Microservices backend. Building microservices with Jhipster JHipster is sponsored by Ippon Technologies(https://www.ippon.tech/). Need cost-effective fractional engineering with US expertise? Fintech and Blockchain Specialized Fractional Engineering