title: Facing Issue with Unit testing in Grails
body: <p>I need to get messagesource to get access <code>message.properties</code> file in simple groovy class(Exception class) so that i am using <code>Holders.getGrailsApplication()</code>. My problem is <code>Holders.getGrailsApplication()</code> is getting null when i execute unit test case.It works fine if i deploy it in web server.
  Variable :-</p>
  
  <pre><code>static def grailsApplicationCntx=Holders.getGrailsApplication().getMainContext().getBean(‘messageSource’)
  </code></pre>
  
  <p>Error:-  </p>
  
  <pre><code>`Failure: testActivateService_Case1(com.xyz.ActivationServiceTests)
  | java.lang.ExceptionInInitializerError
  at java.lang.Class.forName(Class.java:186)
  at com.xyz.DatabaseService.addBankUser(DatabaseService.groovy:11)
  at com.xyz.RegisterService.register(RegisterService.groovy:39)
  at com.xyz.ActivationServiceTests.setUp(ActivationServiceTests.groovy:60)
  Caused by: java.lang.NullPointerException: Cannot invoke method getMainContext() on null object
  at com.xyz.exception.Exception.(Exception.groovy:55)
  … 4 more
  </code></pre>