I could not use mockLogging in grails 1.3.7 with GrailsUnitTestCase. I think there is probably a bug and it can work in Grails 2.0. Here is what I did to get around this:
class Foo {
String name
Long invokeLogTest(String key) {
if (key.empty) {
log.error("key was sent as empty string")
return 10
}
}
}
void testErrorCase() {
def f = new Foo(name:'jp')
f.metaClass.log = [error:{}]
assert 10 == f.invokeLogTest("")
}
source
share