Details
Description
After upgrading from Grails 1.3.2 to 1.3.3, lots of unit tests fail with stack traces like these:
java.lang.NullPointerException at grails.test.MockUtils.mockDomain(MockUtils.groovy:443) at grails.test.MockUtils$mockDomain.call(Unknown Source) at grails.test.GrailsUnitTestCase.mockDomain(GrailsUnitTestCase.groovy:131) at grails.test.GrailsUnitTestCase.mockDomain(GrailsUnitTestCase.groovy:129)
Sample project from Ben Schreur:
svn checkout http://agiletrackingtool.googlecode.com/svn/trunk/ agiletrackingtool-read-onlysvncheckout
Attachments
-
$i18n.getText("admin.common.words.hide")
- test2-bug-report-08072010.zip
- 08/Jul/10 4:16 PM
- 19 kB
- Paul Woods
-
- grails-app/conf/BootStrap.groovy 0.1 kB
- grails-app/conf/BuildConfig.groovy 1 kB
- grails-app/conf/Config.groovy 3 kB
- grails-app/conf/DataSource.groovy 0.8 kB
- grails-app/conf/UrlMappings.groovy 0.2 kB
- grails-app/conf/spring/resources.groovy 0.0 kB
- grails-app/domain/test2/Name.groovy 0.1 kB
- grails-app/i18n/messages.properties 3 kB
- grails-app/i18n/messages_da.properties 3 kB
- grails-app/i18n/messages_de.properties 4 kB
- grails-app/i18n/messages_es.properties 3 kB
- grails-app/i18n/messages_fr.properties 2 kB
- grails-app/i18n/messages_it.properties 2 kB
- grails-app/i18n/messages_ja.properties 2 kB
- grails-app/i18n/messages_nl.properties 3 kB
- grails-app/.../messages_pt_BR.properties 3 kB
- grails-app/.../messages_pt_PT.properties 3 kB
- grails-app/i18n/messages_ru.properties 4 kB
- grails-app/i18n/messages_th.properties 5 kB
- grails-app/.../messages_zh_CN.properties 2 kB
- grails-app/views/error.gsp 2 kB
- grails-app/views/index.gsp 4 kB
- grails-app/views/layouts/main.gsp 0.7 kB
- test/unit/test2/NameTests.groovy 0.3 kB
- application.properties 0.2 kB
$i18n.getText("admin.common.words.show")- test2-bug-report-08072010.zip
- 08/Jul/10 4:16 PM
- 19 kB
- Paul Woods
-
- tomcatError.txt
- 10/Jul/10 5:41 AM
- 7 kB
- Ben Schreur
Activity
- All
- Comments
- Work Log
- History
- Activity
- Git Commits
I also have the same problem.
In unit tests, when the domain is mocked, and .save() is called, I get a NPE. See the attached file for a project.
java.lang.NullPointerException
at grails.test.MockUtils$_addValidateMethod_closure83.doCall(MockUtils.groovy:973)
at grails.test.MockUtils$_addValidateMethod_closure84.doCall(MockUtils.groovy:1014)
at grails.test.MockUtils$_addDynamicInstanceMethods_closure67.doCall(MockUtils.groovy:736)
at grails.test.MockUtils$_addDynamicInstanceMethods_closure67.doCall(MockUtils.groovy)
at test2.NameTests.testSaving(NameTests.groovy:19)
at TestApp$_run_closure4.doCall(TestApp:268)
at TestApp$_run_closure4.call(TestApp)
at TestApp$_run_closure2.doCall(TestApp:225)
at TestApp$_run_closure1_closure21.doCall(TestApp:184)
at TestApp$_run_closure1.doCall(TestApp:171)
at TestApp$_run_closure1.doCall(TestApp.groovy:101)
at gant.Gant$_dispatch_closure5.doCall(Gant.groovy:381)
at gant.Gant$_dispatch_closure7.doCall(Gant.groovy:415)
at gant.Gant$_dispatch_closure7.doCall(Gant.groovy)
at gant.Gant.withBuildListeners(Gant.groovy:427)
at gant.Gant.this$2$withBuildListeners(Gant.groovy)
at gant.Gant$this$2$withBuildListeners.callCurrent(Unknown Source)
at gant.Gant.dispatch(Gant.groovy:415)
at gant.Gant.this$2$dispatch(Gant.groovy)
at gant.Gant.invokeMethod(Gant.groovy)
at gant.Gant.executeTargets(Gant.groovy:590)
at gant.Gant.executeTargets(Gant.groovy:589)
Same issue,
All my unit tests who try to run constraints tests are dead.
Example:
Stacktrace
java.lang.NullPointerException
at grails.test.MockUtils$_addValidateMethod_closure83.doCall(MockUtils.groovy:973)
at grails.test.MockUtils$_addValidateMethod_closure84.doCall(MockUtils.groovy:1014)
at com.arm.nimbus.ProductUnitTests.testConstraints(ProductUnitTests.groovy:26)
Standard Output
-Output from testConstraints-
-Output from testPaths-
Standard Error
-Output from testConstraints-
-Output from testPaths-
You can work around the issue by registering a fake plugin manager. Add these two imports:
import org.codehaus.groovy.grails.plugins.GrailsPluginManager import org.codehaus.groovy.grails.plugins.PluginManagerHolder
and these setUp() and tearDown() methods (or add to existing methods):
protected void setUp() { super.setUp() PluginManagerHolder.pluginManager = [hasGrailsPlugin: { String name -> true }] as GrailsPluginManager } protected void tearDown() { super.tearDown() PluginManagerHolder.pluginManager = null }
import org.codehaus.groovy.grails.plugins.GrailsPluginManager import org.codehaus.groovy.grails.plugins.PluginManagerHolder
protected void setUp() { super.setUp() PluginManagerHolder.pluginManager = [hasGrailsPlugin: { String name -> true }] as GrailsPluginManager } protected void tearDown() { super.tearDown() PluginManagerHolder.pluginManager = null }
Can also confirm that the workaround works for my project.
http://code.google.com/p/agiletrackingtool/source/detail?r=151
Thank you for the fast response!
Deploying created war (grails clean; grails prod war) gives the error logging as attached. There seems to be a relation with the PluginManager.
Using the workaround as suggested for the testcases also seems to work for running on tomcat:
http://code.google.com/p/agiletrackingtool/source/diff?spec=svn152&r=152&format=side&path=/trunk/grails-app/conf/BootStrap.groovy
I can confirm that the workaround works for my test cases in 1.3.3.
Any idea when we'll see that fixed? I'm in the middle of some project and all of the sudden all my tests cases that had to do with saving domain class instances have gone wild.
I confirm that the workaround works also for me (1.3.3 version).
Thanks Burt
Hello, I use Spock Framework for unit test now.
If possible, would you add the code for fix (PluginManagerHolder...) to another point? (for example, _GrailsTest.groovy but this fix is for [grails test-app] command only...)
I'm still seeing this issue using Grails 1.3.4 and Spock 0.5-groovy-1.7-SNAPSHOT. Is this really fixed?
I haven't fixed in Spock yet. Because of the way the Grails test code is structured I had to copy a lot of stuff so it's not using the same codebase.
Hi Luke,
As this issue is closed, is there another one we should watch for the Spock fixes, or will you report the updates here?
execute the tests to see the npe.