Share

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.