Health Studies
200 Oak St SE, Suite 350
Minneapolis, MN 55455
This time, however, the failure isn't due to the lack of metaprogramming on a domain class. It's due to the lack of dependency injection. Specifically, all Grails artifacts get a log object injected into them at run time so that they can easily log messages for later review.
To inject a mock logger for testing purposes, wrap the AdminService class in a mockLogging() method call, as shown in Listing 17:
Listing 17. Service test that will pass, thanks to mockLogging()
void testRestartServer() {
def jdoe = new User(name:"John Doe", role:"user")
def suziq = new User(name:"Suzi Q", role:"admin")
mockLogging(AdminService)
def adminService = new AdminService()
assertTrue adminService.restartServer(suziq)
assertFalse adminService.restartServer(jdoe)
}
|
This time, the test passes as expected. And any log output is sent to System.out. Remember that you can see this output in the HTML reports.
Hope this helps.
-glenn
--
--
You received this message because you are subscribed to the "Groovy Users of Minnesota" group.
To post to this group, send email to groo...@googlegroups.com
To unsubscribe from this group, send email to groovymn-u...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/groovymn?hl=en
---
You received this message because you are subscribed to the Google Groups "Groovy Users of Minnesota" group.
To unsubscribe from this group and stop receiving emails from it, send an email to groovymn+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
It looks like you are trying to call the logger from the test class itself. I'm not sure if a logger is compiled into each test class. Typically, I would just write to System.out or System.err if I wanted to print out stuff from a test case.