问题
I am trying to test my gwt project using GwtTestCase.
But I can't create an instance of a Composite component.
Here is the code and stack trace...
Login.java (My composite component)
public class Login extends Composite{
@UiField
TextBox userName;
@UiField
TextBox password;
@UiField
Button loginButton;
private static LoginUiBinder uiBinder = GWT.create(LoginUiBinder.class);
interface LoginUiBinder extends UiBinder<Widget, Login> {}
public Login() {
initWidget(uiBinder.createAndBindUi(this));
loginButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
Window.alert("clicked");
}
});
}
}
Login.ui.xml(ui binder xml content)
<g:HTMLPanel>
<div>
<g:Label text="username:"></g:Label>
<g:TextBox ui:field="userName"></g:TextBox>
</div>
<div>
<g:Label text="password:"></g:Label>
<g:TextBox ui:field="password"></g:TextBox>
</div>
<g:Button ui:field="loginButton" text="Login"></g:Button>
</g:HTMLPanel>
LoginTest.java (This is my Gwt TesCase)
public class SampleGwtTestCase extends GWTTestCase{
public void test01(){
Login login = new Login();
}
@Override
public String getModuleName() {
return "com.mycompany.TestingGwt";
}
}
Error stack trace
java.lang.RuntimeException: Remote test failed at 192.168.2.15 / Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.19) Gecko/2010031422 Firefox/3.0.19
at com.google.gwt.junit.JUnitShell.processTestResult(JUnitShell.java:1283)
at com.google.gwt.junit.JUnitShell.runTestImpl(JUnitShell.java:1403)
at com.google.gwt.junit.JUnitShell.runTestImpl(JUnitShell.java:1304)
at com.google.gwt.junit.JUnitShell.runTest(JUnitShell.java:652)
at com.google.gwt.junit.client.GWTTestCase.runTest(GWTTestCase.java:441)
at junit.framework.TestCase.runBare(TestCase.java:134)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:124)
at com.google.gwt.junit.client.GWTTestCase.run(GWTTestCase.java:296)
at junit.framework.TestSuite.runTest(TestSuite.java:232)
at junit.framework.TestSuite.run(TestSuite.java:227)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:79)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.lang.Exception: com.google.gwt.core.client.JavaScriptException: (null) @com.google.gwt.dom.client.DOMImplTrident::isOrHasChildImpl(Lcom/google/gwt/dom/client/Node;Lcom/google/gwt/dom/client/Node;)([JavaScript object(22), JavaScript object(26)]): null
at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:249)
at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:571)
at com.google.gwt.dev.shell.ModuleSpace.invokeNativeBoolean(ModuleSpace.java:194)
at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeBoolean(JavaScriptHost.java:35)
at com.google.gwt.dom.client.DOMImplTrident.isOrHasChildImpl(DOMImplTrident.java)
at com.google.gwt.dom.client.DOMImplTrident.isOrHasChild(DOMImplTrident.java:284)
at com.google.gwt.dom.client.Node$.isOrHasChild$(Node.java:280)
at com.google.gwt.user.client.ui.HTMLPanel.addAndReplaceElement(HTMLPanel.java:220)
at com.google.gwt.user.client.ui.HTMLPanel.addAndReplaceElement(HTMLPanel.java:190)
at com.mycompany.client.login.Login_LoginUiBinderImpl$Widgets.build_f_HTMLPanel1(Login_LoginUiBinderImpl.java:95)
at com.mycompany.client.login.Login_LoginUiBinderImpl$Widgets.get_f_HTMLPanel1(Login_LoginUiBinderImpl.java:77)
at com.mycompany.client.login.Login_LoginUiBinderImpl$Widgets.access$0(Login_LoginUiBinderImpl.java:76)
at com.mycompany.client.login.Login_LoginUiBinderImpl.createAndBindUi(Login_LoginUiBinderImpl.java:30)
at com.mycompany.client.login.Login_LoginUiBinderImpl.createAndBindUi(Login_LoginUiBinderImpl.java:1)
at com.mycompany.client.login.Login.<init>(Login.java:50)
at com.mycompany.client.login.SampleGwtTestCase.test01(SampleGwtTestCase.java:11)
at com.mycompany.client.login.__SampleGwtTestCase_unitTestImpl.doRunTest(__SampleGwtTestCase_unitTestImpl.java:7)
at junit.framework.TestCase.runTest(TestCase.java:62)
at com.google.gwt.junit.client.GWTTestCase.runBare(GWTTestCase.java:188)
at com.google.gwt.junit.client.GWTTestCase.__doRunTest(GWTTestCase.java:129)
at com.google.gwt.junit.client.impl.GWTRunner.runTest(GWTRunner.java:390)
at com.google.gwt.junit.client.impl.GWTRunner.doRunTest(GWTRunner.java:318)
at com.google.gwt.junit.client.impl.GWTRunner.access$9(GWTRunner.java:312)
at com.google.gwt.junit.client.impl.GWTRunner$TestBlockListener.onSuccess(GWTRunner.java:107)
at com.google.gwt.junit.client.impl.GWTRunner$InitialResponseListener.onSuccess(GWTRunner.java:63)
at com.google.gwt.junit.client.impl.GWTRunner$InitialResponseListener.onSuccess(GWTRunner.java:1)
at com.google.gwt.user.client.rpc.impl.RequestCallbackAdapter.onResponseReceived(RequestCallbackAdapter.java:232)
at com.google.gwt.http.client.Request.fireOnResponseReceived(Request.java:258)
at com.google.gwt.http.client.RequestBuilder$1.onReadyStateChange(RequestBuilder.java:412)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:338)
at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:219)
at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:571)
at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:279)
at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
at com.google.gwt.core.client.impl.Impl.apply(Impl.java)
at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:249)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:293)
at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:547)
at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:364)
at java.lang.Thread.run(Unknown Source)
Am I doing the test right?
Anything more required in configuration?
The test case works succesfully for classes without ui binders.GWT.create(...)
and native javascript codes also works fine.
回答1:
You have a configuration problem:
java.lang.RuntimeException: Remote test failed at 192.168.2.15 / Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.19) Gecko/2010031422 Firefox/3.0.19
…
Caused by: java.lang.Exception: com.google.gwt.core.client.JavaScriptException: (null) @com.google.gwt.dom.client.DOMImplTrident::isOrHasChildImpl(Lcom/google/gwt/dom/client/Node;Lcom/google/gwt/dom/client/Node;)([JavaScript object(22), JavaScript object(26)]): null
You seem to have fixed the user.agent
property to some value(s) that excludes gecko1_8
, and GWTTestCase
uses a Firefox 3 (Firefox 17 in GWT 2.6.0) emulation. If you don't care about Firefox (for whatever reason), or simply want to run the tests with an IE emulation, pass -runStyle HtmlUnit:IE8
(valid values are FF2, FF3, IE6, IE7 and IE8 up until GWT 2.5.1, and FF17, IE8, IE9 and Chrome in GWT 2.6; you can pass multiple comma-separated values: -runStyle HtmlUnit:IE6,IE8
) in the gwt.args
system property (note: in Eclipse, setting this property in the Arguments tab overrides the options from the GWT tab, so you have to set them there too, e.g. -Dgwt.args="-war www-test -runStyle HtmlUnit:IE8"
)
来源:https://stackoverflow.com/questions/21937576/how-to-test-a-gwt-composite-component-with-ui-binder-using-gwttestcase