Difficulty running grails tests in IntelliJ : Illegal use of nonvirtual function call - grails

Lately I've been trying to run my spock tests in IntelliJ (which used to work beautifully and had great debugging / specific test re-running on failure features) and in the past few months I've began getting the following error:
| Error Error executing script TestApp:
(class: com/company/MyServiceSpec, method: super$2$oldImpl signature:
(Ljava/lang/Object;)Ljava/lang/Object;)
Illegal use of nonvirtual function call (Use --stacktrace to see the full trace)
It's a spock test that runs just fine from the command line, individually (by specifying the class) or in the entire test-app series. Virtually all of the spock and plain old Unit or Integration tests I have on this project give similar failures in IntelliJ.
I've tried twiddling with the run features of the test (having classpath on or off, running an individual method, a whole test class, or the entire test series) with no luck to remedying the situation. I've also done a grails clean and tried re-running them from IntelliJ : that looked as if it worked once and I was able to run the tests for a little while, but then quickly after doing some work the problem now persists.
I know this is a bit of a vague question, but has anyone seen similar failures and found a reliable remedy? I'm on Grails 2.1 and Spock 0.7, same problem in both IntelliJ 12 and 13

I managed to solve this problem adding the following env variable in my configuration:
_JAVA_OPTIONS='-Xverify:none'

First check your configurations and clear out the test that you have ran that are now failing. It is possible you ran the tests as JUnit and now when you are running them again them they are defaulting this behavior.
Note: You can determine if this the issue by running your tests via the command line (e.g. grails test-app unit com.yourPackage.Whatever) if they pass as expected then follow the steps below to clear your saved test configurations in IntelliJ
IntelliJ Steps
Click Run
Click Edit Configurations
In the left pane of the pop up click the arrow to unroll the jUnit tests
Next Click on a test and then click the minus icon ( do this for each to clear them all )
Go to your test you want to run and right click it and make sure you select the grails choice and not jUnit.

Related

How to run Spock unit tests without intializing Grails environment

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.

Running a single integration test/ single test class

I was trying to run a single test or a single class from the grails cli, but no matter what I tried I am unable to find out how to do that. Does anyone of you have an idea what could be the command for doing that?
What I tried so far
test-app -integration -Dtest.single=package.ClassSpec: still runs all of the tests. Replacing package with a wildcard doesnt change anything.
test-app *ClassSpec* -integration: runs 10 actionable tasks, not entirely sure which tests are these, the class doesnt have 10 tests.
I am using Grails 3.3.2
./grailsw test-app MyClass
(without Spec or Test at the end)
http://docs.grails.org/3.1.1/ref/Command%20Line/test-app.html

Grails test cases run twice when I execute grails test-app

I am using Spock plug-in in my grails-2.3.4 application for automated unit and integration tests. When I run grails test-app, all the test cases run two times. Also in test report, every spec file is listed twice. As the application grew, number of test cases also grew, and all of them run twice. This takes double time to execute all of the test cases while development and deploying through Jenkins. Can anyone help me fix it (any help will be appreciated)?
http://grails.github.io/grails-doc/2.3.4/guide/upgradingFromPreviousVersionsOfGrails.html -> Spock included by default
You no longer need to add the Spock plugin to your projects. Simply
create Spock specifications as before and they will be run as unit
tests. In fact, don't install the Spock plugin, otherwise your
specifications will run twice [...].

Debug Spock tests in Intellij IDEA

I'm running Spock tests by "Right click -> Run -> Test Name". How can I run tests in debug mode? Debug icon run tests but doesn't stop on breakpoints
Usually this works fine. If it doesn't, it might be a problem with your IDE and Groovy or Grails. I recommend to try with the latest version of IDEA.
I believe it might be a bug in how the meta classes work in groovy. I found that the break point will work if it is not on a control structure or closure. I found the work around on the intellij forums:
http://youtrack.jetbrains.com/issue/IDEA-82741
I had the "same" issue (not sure if it has the same cause as for the OP)
On my side it was somehow gradle and IntelliJ IDEA related.
IDEA uses per default the gradle build system from the local system when it comes to executing and debugging groovy tests.
But there is an option to run the tests "natively" in IDEA's build system.
I have tried out the IDEA based build system setup for running groovy tests and then it worked.
Setting can be found under Preferences -> Build, Execution, Deployment -> Build Tools -> Gradle
perhaps you should use RightClick -> Debug (Not Run)

Grails - Link checking as part of a continuous integration

So, we have a grails app set up with a Hudson CI build process. We're running unit tests, integration tests, and about to set up Selenium for some functional tests as well.
However, are there any good ways of fully testing a sites links to make sure nothing has broken in a release.
I know there's link checkers in general, but I'd like to have it be a part of the build process, so a build outright fails if something isn't right.
WebTest has a verifyLinks step you could use: http://webtest.canoo.com/webtest/manual/verifyLinks.html
You could install the webtest plugin (it should play nice with Selenium) and just have a single test that checks links.
cheers
Lee
I'm using selenium plugin (http://wiki.hudson-ci.org/display/HUDSON/Seleniumhq+Plugin) with test recorded from both developers and functional people. We start the new instance of the Grails app from the Hudson build with the Postbuild (http://wiki.hudson-ci.org/display/HUDSON/Groovy+Postbuild+Plugin)
What we ended up using was a command line program called linkchecker that we could install by apt-get and we ran from within our build script.

Resources