Search code examples
hibernategrailsgrails-ormintegration-testing

Grails GORM Service class Testing withNewSession()


I am trying to update my test since I made a change on my service class. In a service method I added ("withNewSession")

Domain.withNewSession {
  .. ...
  domain.save()
}

Since I am using the "withNewSession", I am getting method missing exception as this Domain is mocked in my test class.


Solution

  • withNewSession method is not allowed by unit testing. Use inside your test class:

    @org.junit.Before
    void before() {
        DomainClazz.metaClass.static.withNewSession = {Closure c -> c.call() }
    }