August 6, 2010

Grails Integration Test & Dependency Injection How To

Grails: 1.3.3

Today I have been working on a grails app and been trying to get a JMS Message sent to a bug via integration test. Here is how i did it and what you should know.

class JmsServiceMessageSendTests extends GroovyTestCase  {

  def jmsTemplate
  void testSomething() {
   def TibJmsService jmsService = new TibJmsService()
    jmsService.jmsTemplate =  jmsTemplate;
    jmsService.startGameSession(null, "ba");

Note how simple that is... but It took me almost an hour trying to get that integration test to work but no luck, i keep getting a NPE in my JMS template.....

here is the MAIN issue, do not test Integration tests via your IDE (eclipse/IDEA) as they do not start an application context. To Ensure you test works you need to do it via the command line
grails test-app

Then view the result in target\test-reports\html, this means that you can't debug an Integration test via your IDE... hope you find this blog faster than I found the answer.


  1. When we redesigned the test running system for Grails 1.2, we specifically made it possible for IDEs to run integration and functional tests. This was driven by the IDEA guys who were developing this functionality at the time.

    I suggest raising a feature request with your IDE of choice to support this. Best way forward would be to have them get in touch the Grails developers via the mailing list.

  2. Hi George, I am using IDEA and it works like a charm, just make sure you are executing the Integration Tests and not the Unit Tests. (The Run button gives you both options.)

  3. Hey guys thanks for all the comments but I still can't run via IDEA 9...

    Maybe I just can't see that run button options