Reputation: 187529
I'm using IntelliJ 10.0.2 to develop a Grails project. From the Grails view, If I right-click on MyIntegrationTest.groovy and run it individually (by choosing "MyIntegration..." from the right-click menu) the tests therein pass. The tests in this class also pass when I use the "Run Grails target" feature and specify "test-app".
However, if I right-click on Tests:integration and select Run "All Tests", some of the tests in MyIntegrationTest fail because dependencies are not injected. The speed with which the tests run also suggests that the Spring app context is not being created. Is there a way to run all integration tests (or all integration & unit tests) from within IntelliJ without resorting to the Grails command line?
Thanks in advance!
Upvotes: 3
Views: 4555
Reputation: 29857
I encountered a very similar problem but I actually see a slightly different, almost opposite, behaviour in Idea 10.5.2. I have the '.ipr' style project setup. If I right click on the integration test class or the integration test package, I only get the standard 'Run MyIntegrationTests . . .' option and it fails as per the poster's error message (rather than actually fires up the integration context as per the poster's described behavour). However if I right click on the 'Tests: Integration' top level item in Grails view, I get the 'Run "Grails tests:integr..." option, and it works perfectly.
To me this is fine, and I do not have to rebuild my project into the 'directory' based structure.
Upvotes: 1
Reputation: 3723
If its the same case as mine, here's how I've solved it. I had a grails project imported into IDEA with .ipr project style. You can check if your project is .ipr style if you have Project.ipr, Project.iws, Project.iml and Project-grailsPlugins.iml files in your project's main directory.
Close IDEA, backup (for safety if something goes wrong) and remove these 4 files. Then open IDEA and choose New Project. Select "Import grails project from existing sources", select your sources and be sure to select .idea - project style. IDEA should create new project fine. Be sure to check Porject structure (Ctrl-Shift-Alt-S) -> Project Settings -> Modules -> Sources. You should have two directories test/unit and test/integration marked green as Test sources.
If all goes well you should be able to right-click on Tests:integration and Tests:unit project directories. There should be Run "Grails tests:integration" and Run "Grails test:unit" options that you were missing.
Upvotes: 4
Reputation: 5147
With Intellij you've a choise to either run tests as Grails:integration, Grails:unit tests or to run them as plain Unit tests. If you chose to run Unit tests it will work for test/unit only and won't create spring contexts for integration. Right click on test/unit and choose Run->Grails:unit or right click on test/integration and choose Grails:integration. Grails plugin for IDEA should be installed.
Upvotes: 3