Can I run individual Grails integration tests from within IntelliJ?

I've made a integration test in Grails which tests Quartz Jobs. However, I cannot find an easy way to run individual integration tests. Running unit tests is not a problem, but this tests requires the Grails environment to be started, and it's also located in the 'integration' folder. Wouldn't it be easier if Cmd+Shift+F10 would just run 'grails test-app <name of test>' instead of a unit test?

10 comments

CtrlShiftF10 on a test and selecting 'Grails' does that for me. What
does the test extend? Is the test/integration folder marked as a test
source?

0

Here it doesn't do that. My test extends from GroovyTestCase and is a test for testing Quartz Jobs, located in the 'integration' folder. The integration folder is marked as a source folder. Please take a look at the attached screenshot here: http://grab.by/3wFP

0

Which Grails version is it, how is the Grails library called?
Does executing a test for class work, if you do CtrlShiftF10 on the
test class name? How about doing the same on a package?

0

Hi Peter,

It's Grails 1.2.2. I don't understand what you mean with: how is the Grails library called? You mean the name? Or how is it executed?
I also don't understand what you mean with :"Does executing a test for class work". If you mean that if testing overall works, then yes: it works (but you could see that on the screenshot, even though the test itself is failing).

Executing Grails test just runs the test, without starting the container. Reproducing is easy (this is how I did it):

create a new grails app
install the quartz plugin
create a test for the quartz plugin in the integration folder
run the test

You will see that it will just execute the test without starting up the Grails container. When running it on the package, it does work (check http://grab.by/3xLM ) however, but running the class instead of the package results in:

/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home/bin/java -Dfile.encoding=MacRoman -classpath /Applications/Maia-IU-95.4.app/lib/idea_rt.jar:/Applications/Maia-IU-95.4.app/plugins/junit/lib/junit-rt.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home/lib/deploy.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home/lib/dt.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home/lib/javaws.jar:/System/<....large classpath here....>
allseas-ui-grailsPlugins:/Volumes/allseas/allseas-ui/out/production/allseas-ui-grailsPlugins:/Users/erikp/.grails/1.2.2/projects/allseas-ui/plugins/quartz-0.4.2/lib:/Users/erikp/.grails/1.2.2/projects/allseas-ui/plugins/quartz-0.4.2/lib/quartz-1.7.3.jar com.intellij.rt.execution.junit.JUnitStarter -ideVersion5 com.risk.allseas.jobs.ratingtool.RatingToolJobTest

groovy.lang.MissingMethodException: No signature of method: com.risk.allseas.domain.company.Company.save() is applicable for argument types: () values: []
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:54)
at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:51)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:40)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:121)
at com.risk.allseas.jobs.ratingtool.RatingToolJobTest.testJobExecution(RatingToolJobTest.groovy:13)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at com.intellij.junit3.JUnit3IdeaTestRunner.doRun(JUnit3IdeaTestRunner.java:108)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:64)

Process finished with exit code 255

0

By 'called' I meant 'named', thank you. If you try invoking the 'Add
Framework support | Groovy' for your module, you'll see a combobox
containing this Grails distribution. Does it say that the Grails version
here is indeed 1.2.2?

When pressing CtrlShiftF10, I get three options to run the test:
Grails, JUnit and TestNG. Naturally, I select the first one. Don't you
see this choice?

0

Peter, did you check the screenshot? The dialog I made a screenshot of (With Grails, Junit and TestNG) only show up with the package selected, not with the test itself. Did you try the steps to reproduce? When going to the Framework support dialog, I see this: http://grab.by/3yl3

0

I think now I see. The problem is that Grails assumes that all JUnit
test case classes end with 'Tests', while yours ends with 'Test'.
Otherwise any command line customizations just don't work. Please try
renaming your class.

0

Hi Peter,

I see it now. Actually, the thing is: for Grails it doesn't matter. I've tried two times now, one time with Test, and one time with Tests. In Grails, while running grails test-app, both work. In IntelliJ, only the Tests work*, for the Test no popup is show.

This leads me to believe that your statement about "The problem is that Grails assumes that all JUnit test case classes end with 'Tests'" is not completely true.

I renamed my test now however, to stick with the Grails convention of things, so thanks for spotting this!

* = actually, the tests still don't work, but they are executed by IntelliJ. The problem still is the classpath in IntelliJ, which puts Spring twice on the classpath (2.5.6 and 3.0). Grails itself has no problems with this, but this bug (I've created a issue for this) prevents me from running Grails within IntelliJ, and now it also prevents me from running integration tests in IntelliJ. I thought I reported this somewhere, but I cannot find it. This is the error I'm talking about:

/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home/bin/java -Xmx256M -Dgrails.home=/Users/erikp/Downloads/Web/Grails/grails-1.2.2/grails-1.2.2 -Dbase.dir=/Volumes/nidera/Nidera/allseas/allseas-ui -Dtools.jar=/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home/lib/tools.jar -Dgroovy.starter.conf=/Users/erikp/Downloads/Web/Grails/grails-1.2.2/grails-1.2.2/conf/groovy-starter.conf -Dgrails.build.listeners=org.jetbrains.groovy.grails.tests.GrailsIdeaTestListener -Dfile.encoding=MacRoman -classpath /Users/erikp/Downloads/Web/Grails/grails-1.2.2/grails-1.2.2/lib/groovy-all-1.6.8.jar:/Users/erikp/Downloads/Web/Grails/grails-1.2.2/grails-1.2.2/dist/grails-bootstrap-1.2.2.jar org.codehaus.groovy.grails.cli.support.GrailsStarter --main org.codehaus.groovy.grails.cli.GrailsScriptRunner --conf /Users/erikp/Downloads/Web/Grails/grails-1.2.2/grails-1.2.2/conf/groovy-starter.conf --classpath /Applications/Maia-IU-95.4.app/plugins/GrailsGriffon/lib/groovy_mvc_rt.jar:/Users/erikp/.ivy2/cache/org.fontbox/fontbox/jars/fontbox-0.1.0.jar:/Users/erikp/.ivy2/cache/com.nidera/commons-util/jars/commons-util-2.1.0.jar:/Users/erikp/.ivy2/cache/commons-cli/commons-cli/jars/commons-cli-1.2.jar:/Users/erikp/.ivy2/cache/javax.annotation/jsr250-api/jars/jsr250-api-1.0.jar:/Users/erikp/.ivy2/cache/joda-time/joda-time/jars/joda-time-1.6.jar:/Users/erikp/.ivy2/cache/org.slf4j/slf4j-api/jars/slf4j-api-1.5.10.jar:/Users/erikp/.ivy2/cache/org.slf4j/slf4j-log4j12/jars/slf4j-log4j12-1.5.10.jar:/Users/erikp/.ivy2/cache/org.springframework/spring/jars/spring-2.5.6.jar:/Users/erikp/.ivy2/cache/commons-logging/commons-logging/jars/commons-logging-1.1.1.jar:/Users/erikp/.ivy2/cache/org.apache.tika/tika-core/bundles/tika-core-0.6.jar:/Users/erikp/.ivy2/cache/org.apache.tika/tika-parsers/bundles/tika-parsers-0.6.jar:/Users/erikp/.ivy2/cache/org.apache.commons/commons-compress/jars/commons-compress-1.0.jar:/Users/erikp/.ivy2/cache/org.apache.pdfbox/pdfbox/jars/pdfbox-0.8.0-incubating.jar:/Users/erikp/.ivy2/cache/org.apache.poi/poi/jars/poi-3.6.jar:/Users/erikp/.ivy2/cache/org.apache.poi/poi-scratchpad/jars/poi-scratchpad-3.6.jar:/Users/erikp/.ivy2/cache/org.apache.poi/poi-ooxml/jars/poi-ooxml-3.6.jar:/Users/erikp/.ivy2/cache/org.apache.poi/poi-ooxml-schemas/jars/poi-ooxml-schemas-3.6.jar:/Users/erikp/.ivy2/cache/org.apache.xmlbeans/xmlbeans/jars/xmlbeans-2.3.0.jar:/Users/erikp/.ivy2/cache/org.apache.geronimo.specs/geronimo-stax-api_1.0_spec/bundles/geronimo-stax-api_1.0_spec-1.0.1.jar:/Users/erikp/.ivy2/cache/org.ccil.cowan.tagsoup/tagsoup/jars/tagsoup-1.2.jar:/Users/erikp/.ivy2/cache/asm/asm/jars/asm-3.1.jar:/Users/erikp/.ivy2/cache/com.drewnoakes/metadata-extractor/jars/metadata-extractor-2.4.0-beta-1.jar:. test-app -integration com.nidera.risk.allseas.jobs.ratingtool.RatingToolJob
Testing started at 11:10 AM ...
Welcome to Grails 1.2.2 - http://grails.org/
Licensed under Apache Standard License 2.0
Grails home is set to: /Users/erikp/Downloads/Web/Grails/grails-1.2.2/grails-1.2.2
Base Directory: /Volumes/nidera/Nidera/allseas/allseas-ui
Resolving dependencies...
Dependencies resolved in 2394ms.
Running script /Users/erikp/Downloads/Web/Grails/grails-1.2.2/grails-1.2.2/scripts/TestApp.groovy
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/Users/erikp/.ivy2/cache/org.slf4j/slf4j-log4j12/jars/slf4j-log4j12-1.5.10.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/Users/erikp/.ivy2/cache/org.slf4j/slf4j-log4j12/jars/slf4j-log4j12-1.5.8.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
Environment set to test
Clover: Using config: [:]
Clover: Compile start.
[mkdir] Created dir: /Volumes/nidera/Nidera/allseas/allseas-ui/target/test-reports/html
[mkdir] Created dir: /Volumes/nidera/Nidera/allseas/allseas-ui/target/test-reports/plain
Starting integration test phase ...
Clover: Compile start.
Clover: Compile start.
[junitreport] Processing /Volumes/nidera/Nidera/allseas/allseas-ui/target/test-reports/TESTS-TestSuites.xml to /var/folders/rF/rFr56bJ8EF4Rt362XK-vMU+++TI/-Tmp-/null963610045
[junitreport] Loading stylesheet jar:file:/Users/erikp/.ivy2/cache/org.apache.ant/ant-junit/jars/ant-junit-1.7.1.jar!/org/apache/tools/ant/taskdefs/optional/junit/xsl/junit-frames.xsl
[junitreport] Transform time: 516ms
[junitreport] Deleting: /var/folders/rF/rFr56bJ8EF4Rt362XK-vMU+++TI/-Tmp-/null963610045
Tests PASSED - view reports in target/test-reports
Clover: Tests ended
Error executing script TestApp: org.codehaus.groovy.grails.commons.spring.ReloadAwareAutowireCapableBeanFactory.setParameterNameDiscoverer(Lorg/springframework/core/ParameterNameDiscoverer;)V
java.lang.NoSuchMethodError: org.codehaus.groovy.grails.commons.spring.ReloadAwareAutowireCapableBeanFactory.setParameterNameDiscoverer(Lorg/springframework/core/ParameterNameDiscoverer;)V
at _GrailsBootstrap_groovy$_run_closure2_closure11.doCall(_GrailsBootstrap_groovy:89)
at _GrailsBootstrap_groovy$_run_closure2_closure11.doCall(_GrailsBootstrap_groovy)
at _GrailsSettings_groovy$_run_closure10.doCall(_GrailsSettings_groovy:282)
at _GrailsSettings_groovy$_run_closure10.call(_GrailsSettings_groovy)
at _GrailsBootstrap_groovy$_run_closure2.doCall(_GrailsBootstrap_groovy:79)
at _GrailsBootstrap_groovy$_run_closure6.doCall(_GrailsBootstrap_groovy:137)
at _GrailsTest_groovy$_run_closure9.doCall(_GrailsTest_groovy:309)
at _GrailsTest_groovy$_run_closure9.doCall(_GrailsTest_groovy)
at _GrailsTest_groovy$_run_closure1_closure21.doCall(_GrailsTest_groovy:193)
at _GrailsTest_groovy$_run_closure1.doCall(_GrailsTest_groovy:171)
at TestApp$_run_closure1.doCall(TestApp.groovy:102)
at gant.Gant$_dispatch_closure4.doCall(Gant.groovy:324)
at gant.Gant$_dispatch_closure6.doCall(Gant.groovy:334)
at gant.Gant$_dispatch_closure6.doCall(Gant.groovy)
at gant.Gant.withBuildListeners(Gant.groovy:344)
at gant.Gant.this$2$withBuildListeners(Gant.groovy)
at gant.Gant$this$2$withBuildListeners.callCurrent(Unknown Source)
at gant.Gant.dispatch(Gant.groovy:334)
at gant.Gant.this$2$dispatch(Gant.groovy)
at gant.Gant.invokeMethod(Gant.groovy)
at gant.Gant.processTargets(Gant.groovy:495)
at gant.Gant.processTargets(Gant.groovy:480)
Error executing script TestApp: org.codehaus.groovy.grails.commons.spring.ReloadAwareAutowireCapableBeanFactory.setParameterNameDiscoverer(Lorg/springframework/core/ParameterNameDiscoverer;)V
Empty test suite.

Process finished with exit code 1

0

This leads me to believe that your statement about "The problem is that Grails assumes that all JUnit test case classes end with 'Tests'" is not completely true.

Nevertheless, it is. :) Because if you run your test as 'grails run-app
-integration RatingToolJob', it won't run, as it won't run as 'grails
run-app -integration RatingToolJobTest'. And I know of no way to run
separate test cases via command line. Do you?

  • = actually, the tests still don't work, but they are executed by IntelliJ. The problem still is the classpath in IntelliJ, which puts Spring twice on the classpath (2.5.6 and 3.0). Grails itself has no problems with this, but this bug (I've created a issue for this) prevents me from running Grails within IntelliJ, and now it also prevents me from running integration tests in IntelliJ. I thought I reported this somewhere, but I cannot find it. This is the error I'm talking about:

The issue with excessive dependencies in --classpath should be fixed in
the last RC (95.24), please try it.

0

Check, good one! I didn't know there was a new RC, I'll download it and let you know. I hope that for the real 9.0.2 you could also take a look at this issue: http://youtrack.jetbrains.net/issue/IDEA-53626?projectKey=IDEA , which I've just created. It's sort of blocking me being able to run Unit tests from IntelliJ. Thanks for your great support so far! Much appreciated!

0

Please sign in to leave a comment.