When unit testing services in Grails and Spock you can run into issues when your service logs messages. The problem is that Spock doesn’t automatically add the log property to your service. You’ll find most of the answer here but it’s not complete and doesn’t work as is. Most of the time you also don’t need the actual log messages, you’re testing the code. So, here’s the simple solution. Add this method to your Spock test class:

private def mockLog(def service) {
    def impl = [
            debug:{String message ->
                println "debug: ${message}"
            info:{String message ->
                println "info:  ${message}"
            warn:{String message ->
                println "warn:  ${message}"
            error:{String message ->
                println "error: ${message}"

    def logInstance = impl as org.apache.commons.logging.Log
    service.metaClass.log = logInstance

Now, in your test setup, just call the method mockLog(myService). If you don’t want the log messages littering your output, then replace the println with no-op calls.