I would not go along this route. Instead, I would move the request to the domain class as a static search method and test it directly in the integration test with real data. Then you can easily mock the helper method when it is called in a controller or service test.
class YourDomainClass { ... static List<YourDomainClass> findFooBar() { YourDomainClass.withCriteria { ... } } }
Then in unit test:
def results = [instance1, instance2, instance3] YourDomainClass.metaClass.static.findFooBar = { -> results }
Thus, you verify that the query works with the database in memory in the integration test, but it is easy to mock it in unit tests.
Burt beckwith
source share