Debug Spock tests in Intellij IDEA - grails

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)

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.

How to Invoke and Kill Executable in TFS Build Definition?

I am developing a Web API solution. This EXE listens and responds to localhost:8080/abc/.
I have developed a Test solution for this executable.These tests simply verify responses from localhost:8080/abc/.
I have already successfully created a build definition that:
Gets and compiles the solution.
Gets and compiles the tests.
Runs the tests.
My problem here is, the tests are failing, because the EXE isn't up and running. How do I bring up the EXE for the tests, and kill it after the tests are done? Could this be done solely in the build definition itself? Say via MSBuild Arguments in the "Build process parameters"? Hopefully there is a simple solution to this...
Thanks in advance!
I can't manage to solve this in the build definition alone.
I found the solution in modifying the build template (via Edit Build Definition... -> Process), by adding InvokeProcess controls in the build flow. Have these controls call BAT files that instead run / kill the EXE.

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

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.

debug grails integration tests in spring STS

Does anybody know if there is a way to debug integration tets using the built in functionality of Spring STS ?
I don't know if this is what you meant, but you can right click on your test file in the project explorer and then select Debug As -> Grails Command (test-app). This will load grails and run your test in debug mode.
What I haven't figured out is how to re-run the test through the JUnit view, once the test has been run once. It keeps throwing a warning saying that tests must be run in debug mode and that I need to have "Keep Junit running" in the launch configuration. There is no such setting for integration tests and I suspect that it might be because the framework gets reloaded on every test run.
there is an open issue....
https://issuetracker.springsource.com/browse/STS-551
but there appears to be a work around
http://www.pubbs.net/201003/grails/8778-re-grails-user-how-to-debug-in-sts.html

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