RootPanel.get("aaa") in Junit test throws NPE

19 views
Skip to first unread message

Владимир Петрухин

unread,
Jun 26, 2009, 12:45:29 PM6/26/09
to Google Web Toolkit
I generate a simple project with maven gwt plugin:

mvn archetype:generate \
-DarchetypeGroupId=org.codehaus.mojo \
-DarchetypeArtifactId=gwt-maven-plugin \
-DarchetypeVersion=1.1 \
-DgroupId=myGroupId \
-DartifactId=myArtifactId

In GwtTestSample I change:

public void testSomething()
{
final Label label = new Label ( "gwt-maven-plugin Archetype ::
Project myGroupId.myArtifactId" );
RootPanel.get("aaa").add( label );
}

And in Application.html i add <div id="aaa"></div>

All works ok, but in JUnit test (mvn gwt:test) RootPanel.get("aaa")
throws

java.lang.NullPointerException
[INFO] at myGroupId.client.GwtTestSample.testSomething
(GwtTestSample.java:23)
[INFO] at myGroupId.client.__GwtTestSample_unitTestImpl.doRunTest
(transient source for myGroupId.client.__GwtTestSample_unitTestImpl:7)
[INFO] at junit.framework.TestCase.runTest(TestCase.java:62)
[INFO] at com.google.gwt.junit.client.GWTTestCase.runBare
(GWTTestCase.java:206)
[INFO] at com.google.gwt.junit.client.GWTTestCase.__doRunTest
(GWTTestCase.java:137)
[INFO] at com.google.gwt.junit.client.impl.GWTRunner.runTest
(GWTRunner.java:188)
[INFO] at com.google.gwt.junit.client.impl.GWTRunner.doRunTest
(GWTRunner.java:163)
[INFO] at com.google.gwt.junit.client.impl.GWTRunner.access$3
(GWTRunner.java:157)
[INFO] at com.google.gwt.junit.client.impl.GWTRunner
$JUnitHostListener.onSuccess(GWTRunner.java:61)
[INFO] at com.google.gwt.junit.client.impl.GWTRunner
$JUnitHostListener.onSuccess(GWTRunner.java:1)
[INFO] at
com.google.gwt.user.client.rpc.impl.RequestCallbackAdapter.onResponseReceived
(RequestCallbackAdapter.java:215)
[INFO] at
com.google.gwt.http.client.Request.fireOnResponseReceivedImpl
(Request.java:264)
[INFO] at com.google.gwt.http.client.Request.fireOnResponseReceived
(Request.java:229)
[INFO] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[INFO] at sun.reflect.NativeMethodAccessorImpl.invoke
(NativeMethodAccessorImpl.java:39)
[INFO] at sun.reflect.DelegatingMethodAccessorImpl.invoke
(DelegatingMethodAccessorImpl.java:25)
[INFO] at java.lang.reflect.Method.invoke(Method.java:597)
[INFO] at com.google.gwt.dev.shell.MethodAdaptor.invoke
(MethodAdaptor.java:103)
[INFO] at com.google.gwt.dev.shell.moz.MethodDispatch.invoke
(MethodDispatch.java:80)
[INFO] at org.eclipse.swt.internal.gtk.OS._g_main_context_iteration
(Native Method)
[INFO] at org.eclipse.swt.internal.gtk.OS.g_main_context_iteration
(OS.java:1428)
[INFO] at org.eclipse.swt.widgets.Display.readAndDispatch
(Display.java:2840)
[INFO] at com.google.gwt.dev.SwtHostedModeBase.processEvents
(SwtHostedModeBase.java:235)
[INFO] at com.google.gwt.dev.HostedModeBase.pumpEventLoop
(HostedModeBase.java:558)
[INFO] at com.google.gwt.junit.JUnitShell.runTestImpl(JUnitShell.java:
652)
[INFO] at com.google.gwt.junit.JUnitShell.runTest(JUnitShell.java:
346)
[INFO] at com.google.gwt.junit.client.GWTTestCase.runTest
(GWTTestCase.java:219)
[INFO] at junit.framework.TestCase.runBare(TestCase.java:134)
[INFO] at junit.framework.TestResult$1.protect(TestResult.java:110)
[INFO] at junit.framework.TestResult.runProtected(TestResult.java:
128)
[INFO] at junit.framework.TestResult.run(TestResult.java:113)
[INFO] at junit.framework.TestCase.run(TestCase.java:124)
[INFO] at com.google.gwt.junit.client.GWTTestCase.run
(GWTTestCase.java:132)
[INFO] at junit.framework.TestSuite.runTest(TestSuite.java:232)
[INFO] at junit.framework.TestSuite.run(TestSuite.java:227)
[INFO] at org.codehaus.mojo.gwt.test.MavenTestRunner.doRun
(MavenTestRunner.java:105)
[INFO] at junit.textui.TestRunner.start(TestRunner.java:180)
[INFO] at org.codehaus.mojo.gwt.test.MavenTestRunner.main
(MavenTestRunner.java:63)


Help.
Thanks.

hazy1

unread,
Jul 3, 2009, 10:58:36 PM7/3/09
to Google Web Toolkit
I have the same problem. No solution/work around that I know of.

On Jun 26, 12:45 pm, Владимир Петрухин <mylonglongn...@gmail.com>
wrote:

hazy1

unread,
Jul 6, 2009, 9:22:56 PM7/6/09
to Google Web Toolkit
The work around I ended up using is to parameterize the RootPanel.get
("xxx") call with a public static member. In my JUnit test cases, I
set this public static to null prior to calling onModuleLoad.
Reply all
Reply to author
Forward
0 new messages