Saturday 16 June 2012

Fixing grails problem: java.lang.IllegalStateException: Method on class [] was used outside of a Grails application. If running in the context of a test using the mocking API or bootstrap Grails correctly.


So I was getting this exception when I am writing a unit test for a controller for an application that uses the grails mongo gorm plugin:

 java.lang.IllegalStateException: Method on class [com.tweetcommendation.Tweetcommendation] was used outside of a Grails application. If running in the context of a test using the mocking API or bootstrap Grails correctly.  

I'm also writing the unit using the annotation style (ala 2.0+ style). It turns out that this problem comes up when you don't define the @Mock annotation with the domain class (which happens to be mapped with mongo).
So add in the domain class with the @Mock annotation:


 @Mock([DomainClassMappedWithMongo])  


1 comment:

  1. Reading https://grails.org/2.3.8+Release+Notes and using the recommended plugins solved my problem

    ReplyDelete