The moose likes Groovy and the fly likes Mocking grailsApplication in Integration testCases Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Other Languages » Groovy
Reply Bookmark "Mocking grailsApplication in Integration testCases" Watch "Mocking grailsApplication in Integration testCases" New topic
Author

Mocking grailsApplication in Integration testCases

Amit Sharma
Ranch Hand

Joined: Nov 22, 2005
Posts: 87
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.


Amit Sharma SCJP 1.4, SCWCD 5, OCUP-100(UML)
Gregg Bolinger
Sheriff

Joined: Jul 11, 2001
Posts: 15021

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.


My Blog | DZone Articles
Gregg Bolinger
Sheriff

Joined: Jul 11, 2001
Posts: 15021

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

Joined: Nov 22, 2005
Posts: 87
Hi Gregg

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

Thanks and Regards
Amit

This message was edited 1 time. Last update was at by Amit Sharma

 
 
subject: Mocking grailsApplication in Integration testCases
 
developer file tools

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture