Reputation: 1098
In tests i need to override function of some domain class, like this
SomeDomain.countBySomeField(Paramater)
To solve this i tried
@Mock([SomeDomain])
class SomeDomainTests ...
...
void test() {
SomeDomain.metaClass.static.countBySomeField = { -> 1}
}
But when this method invoke in controller(that was invoked by test), what i expet not happen. Probably, you say go read documentation, but i didnt find someting that will tell me how to do this. I will be grateful for any article or example that can say me where im wrong.
Upvotes: 0
Views: 1219
Reputation: 1098
I solve my problem by doing this
@TestFor(SomeController)
@Mock([SomeDomain])
@TestMixin(DomainClassUnitTestMixin)
class SomeControllerTests {
...
void test() {
SomeDomain.metaClass.'static'.countBySomeParam = { a -> 0}
}
}
Upvotes: 4