Click( ) not firing in GWTTestCase?

26 views
Skip to first unread message

fke...@gmail.com

unread,
Nov 1, 2009, 8:41:19 PM11/1/09
to Google Web Toolkit
I'm trying out GWT 2.0 and in a GWTTestCase I wrote

lv.loginButton.click();

and "lv" is a LoginView, where I defined:

loginButton = new Button("Log in");
loginButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
loginCallback.onSuccess(null);
}
});

I set loginCallback appropriately, but the code there doesn't get
executed. If I execute the callback's onSuccess method directly, it
works, but it doesn't work if I try the click( ) way.

Is this a bug of mine or a bug of GWT 2.0? The LoginView works
perfectly well in development mode, so the code itself is not at
fault. Of course, I have known myself to be at fault...

Thomas Broyer

unread,
Nov 2, 2009, 4:35:57 AM11/2/09
to Google Web Toolkit
It might very well be a bug in HtmlUnit if that's the runstyle you're
using to run your tests (it's the default one in MS1 and MS2), but
according to this test (from 2.0.0-ms1) it should work (the test isn't
annotated with @DoNotRunWith(Platform.Htmlunit))
http://code.google.com/p/google-web-toolkit/source/browse/tags/2.0.0-ms1/user/test/com/google/gwt/user/client/ui/ButtonTest.java#68

Try running your tests manually to confirm (add "-runStyle Manual" to
the -Dgwt.args sysprop; it'll ask you to open a URL in a browser, just
like with DevMode).

fke...@gmail.com

unread,
Nov 2, 2009, 6:24:40 PM11/2/09
to Google Web Toolkit
On Nov 2, 7:35 am, Thomas Broyer <t.bro...@gmail.com> wrote:

> It might very well be a bug in HtmlUnit if that's the runstyle you're
> using to run your tests (it's the default one in MS1 and MS2), but
> according to this test (from 2.0.0-ms1) it should work (the test isn't
> annotated with @DoNotRunWith(Platform.Htmlunit))http://code.google.com/p/google-web-toolkit/source/browse/tags/2.0.0-...
>
> Try running your tests manually to confirm (add "-runStyle Manual" to
> the -Dgwt.args sysprop; it'll ask you to open a URL in a browser, just
> like with DevMode).

When running manually, the test still fails, but now it produces:

com.google.gwt.junit.client.TimeoutException: A timeout expired after
1000ms elapsed.
at com.google.gwt.junit.client.GWTTestCase$KillTimer.run
(GWTTestCase.java:56)
at com.google.gwt.user.client.Timer.fire(Timer.java:141)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke
(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke
(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
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:146)
at
com.google.gwt.dev.shell.BrowserChannel.reactToMessagesWhileWaitingForReturn
(BrowserChannel.java:1704)
at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript
(BrowserChannelServer.java:144)
at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke
(ModuleSpaceOOPHM.java:120)
at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:
518)
at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject
(ModuleSpace.java:275)
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:188)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke
(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke
(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
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:146)
at com.google.gwt.dev.shell.BrowserChannel.reactToMessages
(BrowserChannel.java:1660)
at com.google.gwt.dev.shell.BrowserChannelServer.processConnection
(BrowserChannelServer.java:354)
at com.google.gwt.dev.shell.BrowserChannelServer.run
(BrowserChannelServer.java:192)
at java.lang.Thread.run(Thread.java:636)

Any ideas? Thanks!

fke...@gmail.com

unread,
Nov 2, 2009, 7:02:52 PM11/2/09
to Google Web Toolkit
By the way, I had added a 1000 ms delay just in case; without it, the
test failed anyway, as the first time, when an expected condition
wasn't met:

junit.framework.AssertionFailedError: expected=1 actual=0
at junit.framework.Assert.fail(Assert.java:197)
at junit.framework.Assert.assertEquals(Assert.java:94)
at junit.framework.Assert.assertEquals(Assert.java:43)
at com.fkereki.mvptest.client.LoginViewGwtTest.testLoginView
(LoginViewGwtTest.java:51)
at
com.fkereki.mvptest.client.__LoginViewGwtTest_unitTestImpl.doRunTest
(transient source for
com.fkereki.mvptest.client.__LoginViewGwtTest_unitTestImpl:7)
...etc

Thanks again!

Thomas Broyer

unread,
Nov 2, 2009, 7:17:07 PM11/2/09
to Google Web Toolkit


On 3 nov, 01:02, "fker...@gmail.com" <fker...@gmail.com> wrote:
>
> junit.framework.AssertionFailedError:  expected=1 actual=0
>         at junit.framework.Assert.fail(Assert.java:197)
>         at junit.framework.Assert.assertEquals(Assert.java:94)
>         at junit.framework.Assert.assertEquals(Assert.java:43)
>         at com.fkereki.mvptest.client.LoginViewGwtTest.testLoginView
> (LoginViewGwtTest.java:51)

Could you show us the code of the failing test (around line 51) ?

fke...@gmail.com

unread,
Nov 2, 2009, 7:30:50 PM11/2/09
to Google Web Toolkit
> Could you show us the code of the failing test (around line 51) ?

I cleaned up and simplified the code as much as possible. I created a
boolean attribute, wasCalled. I created a callback; in it, I set
wasCalled=true. (So, this is a poor man's mock object...)

The code up to the failure is:

wasCalled = false;
lv.loginCallback.onSuccess(null);
assertTrue(wasCalled);

wasCalled = false;
lv.loginButton.click();
assertTrue(wasCalled);

The first assertTrue(...) succeeds --so I'm sure the callback works--
but the second fails:

junit.framework.AssertionFailedError: null
at junit.framework.Assert.fail(Assert.java:197)
at junit.framework.Assert.assertTrue(Assert.java:188)
at junit.framework.Assert.assertTrue(Assert.java:183)
at com.fkereki.mvptest.client.LoginViewGwtTest.testLoginView
(LoginViewGwtTest.java:44)
at
com.fkereki.mvptest.client.__LoginViewGwtTest_unitTestImpl.doRunTest
(transient source for
com.fkereki.mvptest.client.__LoginViewGwtTest_unitTestImpl:7)
at junit.framework.TestCase.runTest(TestCase.java:62)
...etc.

By the way, without the first three lines, the result is exactly the
same.

If I run the actual program, the callback does work (and the user
manages to log in).

Thanks again for your help!
Reply all
Reply to author
Forward
0 new messages