0

I have a Spock unit test in a Grails app. In IntelliJ IDEa I can either run it with grails environment and then it means I wait a minute until the environment loads to run the test even though I do not need the environment.

The other option is to run it with JUnit. This works nicely in a Grails app without my own plugins. However, when I run it in a Grails app that has a plugin of another Grails app I have, it crashes on NoClassFound. It does not see the classes from the plugin that I included.

When I checked in IDEa the project structure, indeed the sources nowhere include a folder where the plugin classes would be included. For some reason the plugins in plugins section in BuildConfig.groovy do not appear in the classpath anywhere, they are not found in the external libraries section or anywhere else.

Is there a way to tell grails not to spin up its environment when running some of my tests? Or how can I include my plugin in the classpath for Groovyc to see it when building for testing?

The problem occurs also when simply pressing Build Project in IntelliJ IDEa. The project we are working with is simply run with grails and is never built (beyond how grails builds it). When you try to build it in IDEa, it fails on NoClassDefFound of plugin class.

Versions:

  • IntelliJ IDEa 2021.2
  • Grails 2.5.6

EDIT: Ok, it seems like grails apps are to be tested via their command-linke with grails test-app. When Grails runs in interactive mode, test-app won't have to reinitialize the environment, cause it's already running, so it runs faster.

However, as I found here Slow Grails test starting in Intellij IDEA it seems like there's no way to run grails in interactive mode from within IDEa in a way that would enable IDEa test runs to use such interactive console. Which means I'm forced to run tests via command-line. Not happy.

Edit 2: At some point in time I have managed to get the compiled tested.class to the out folder. This enabled running the test instantly via IDEa circumventing the Grails glory. However, I have no idea how I got it to out folder and after removing it I am unable to compile it again and get it there.

Ev0oD
  • 1,395
  • 16
  • 33
  • if your unit test needs more than 1 plugin, it's usually NOT a unit test – injecteer Oct 01 '21 at 14:20
  • The unit test itself does not need the plugin. But to run the unit test, the whole project needs to be built at least once. (at least idea forces it) and building the project causes failure due to the plugin classes not being included in classpath – Ev0oD Oct 01 '21 at 14:27
  • you can extract some code from the plugins into generic groovy/java libraries and use them as dependencies for the unit test – injecteer Oct 01 '21 at 14:29
  • doing that manually does not seem maintainable. Could I make the entire plugin into a test dependency? Though it still seems weird that I have to do this. Smells like a workaround – Ev0oD Oct 01 '21 at 14:32
  • This smells like a well-thought modularization approach, unless you do it AFTER the whole project is already in place. If you want to make those modules unit-testable you have to invest some time into it – injecteer Oct 01 '21 at 14:48

0 Answers0