Why automatic insertion of the log object does not always work in the grail?

In the grails-framework, some objects use log. This is usually introduced by the grail. It works when running grails test-app . But the same test (integration test) fails when doing grails test-app -integration .

What is wrong here, and can I somehow force the injection of the log object?

+4
source share
3 answers

What version of grails are you using? It works great for both situations for me on 1.0.4 (last).

I create a new empty application and create a service class with an integration test:

FooService.groovy:

 class FooService { def logSomething(message) { log.error(message) return true } } 

FooServiceTests.groovy:

 class FooServiceTests extends GroovyTestCase { def fooService void testSomething() { assert fooService.logSomething("it works") } } 

When starting only a test application, I get a log message:

 % grails test-app Welcome to Grails 1.0.4 - http://grails.org/ .... ------------------------------------------------------- Running 1 Integration Test... Running test FooServiceTests... testSomething...[4174] service.FooService it works SUCCESS Integration Tests Completed in 440ms ------------------------------------------------------- ... 

When doing only integration tests, it also works:

 % grails test-app -integration Welcome to Grails 1.0.4 - http://grails.org/ .... ------------------------------------------------------- Running 1 Integration Test... Running test FooServiceTests... testSomething...[4444] service.FooService it works SUCCESS Integration Tests Completed in 481ms ------------------------------------------------------- .... 

Are you going to get together with the registrar class (or redefine any metaclass stuff on the registrar, in any previous integration classes or unit tests, and not then reinitialize the metaClass?

+3
source

I just had this exact problem and it is very easy to solve it by calling the mockLogging function:

 void testTheMagic() { mockLogging(MyMagicService) def testService = new MyMagicService() ... } 

(using Grails 1.1.1 if that matters)

+1
source

I am using 1.3.2 and the test entry works fine. Just make sure you specify the log4j configuration for your test environment.

0
source

All Articles