File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Mocking grailsApplication in Integration testCases

 
Amit Sharma
Ranch Hand
Posts: 87
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I have one service class which is using grailsApplication to get some value from properties file.But while writing testcase for it , it is giving null pointer exception for grailsApplication . I have googled and found some ways but they are not working in my code. Please suggest some way to implement this.
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
grailsApplication only gets wired up for Integration tests. The simplest solution is to switch your test from a unit test to an integration test. Which makes sense, when testing a service, in my opinion.
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I also found this which looks to solve your problem...

http://old.nabble.com/Testing-taglibs:-mocking-grailsApplication.config-td21309687.html

In your case, something like...

MyServiceClass.metaClass.getGrailsApplication = {-> return [config: [:]] }
 
Amit Sharma
Ranch Hand
Posts: 87
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Gregg

I am writing integration testcases and its still giving null pointer exception.

Thanks and Regards
Amit
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic