I've following problem in grails 2.1.0. I've domain which has named query. In service I call list() method on result of this named query:
List result = Domain.namedQuery(someParams).list()
So, I'd like mock result in my service's unit test. Is there any option to do it?
I believe you can through altering the metaclass. Just be sure to @Mock
the class as well so you don't get test pollution:
Domain.static.metaclass.namedQuery = { someParams ->
// Assert and return data
}
Also be sure that you match the type and number of params exactly or it may not work.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.