JUnit testing with GWT

73 views
Skip to first unread message

Raja

unread,
Aug 18, 2011, 4:06:55 AM8/18/11
to Google Web Toolkit
Hi,

Can someone please guide me in writing GWT Junit test cases?
I'm new to Junit too.

what files are involved and what to mention in which file?etc?

Thanks,
Raja

Adolfo Panizo Touzon

unread,
Aug 18, 2011, 5:32:50 AM8/18/11
to google-we...@googlegroups.com
Hi,

take a look here.

For a interesting example take a look to the included file (ValidationTest.java).

Regards.

2011/8/18 Raja <grsva...@gmail.com>

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.




--
El precio es lo que pagas. El valor es lo que recibes.
Warren Buffet
ValidationTest.java

Raja Shekhar

unread,
Aug 18, 2011, 5:50:42 AM8/18/11
to google-we...@googlegroups.com
Hi,

i have already gone through that link.

apart from the text class, do i need to have any xml file for configuration?
i'm using smartgwt library for xpath functions.
i can't understand how to debug the error.


here is my code:

public boolean isPasswordExpired() {


      int expire = Integer.parseInt(XMLTools.selectString(credentialXML, "//domain:credential/user/passwd/@expire",namespace));

      int days = Integer.parseInt(XMLTools.selectString(credentialXML, "//domain:credential/user/passwd/@days",namespace));

      if( expire == 1 && days <= 0 )

            return true;

      return false;

    }   


my test case:

public void testisPasswordExpired(){

        Abc cr = Abc.getInstance();

        assertTrue("Password Expired, Test Failed ",cr.isPasswordExpired());

}



here is the error that i'm getting:

java.lang.RuntimeException: Remote test failed at 10.64.123.39 / 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:1288)

                at com.google.gwt.junit.JUnitShell.runTestImpl(JUnitShell.java:1408)

                at com.google.gwt.junit.JUnitShell.runTestImpl(JUnitShell.java:1309)

                at com.google.gwt.junit.JUnitShell.runTest(JUnitShell.java:650)

                at com.google.gwt.junit.client.GWTTestCase.runTest(GWTTestCase.java:441)

                at junit.framework.TestCase.runBare(TestCase.java:130)

                at junit.framework.TestResult$1.protect(TestResult.java:106)

                at junit.framework.TestResult.runProtected(TestResult.java:124)

                at junit.framework.TestResult.run(TestResult.java:109)

                at junit.framework.TestCase.run(TestCase.java:120)

                at com.google.gwt.junit.client.GWTTestCase.run(GWTTestCase.java:296)

                at junit.framework.TestSuite.runTest(TestSuite.java:230)

                at junit.framework.TestSuite.run(TestSuite.java:225)

                at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)

                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): null

                at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:237)

                at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:132)

                at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:561)

                at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:269)

                at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)

                at com.smartgwt.client.data.XMLTools.selectString(XMLTools.java)

                at com.verifone.isd.client.Credential.isPasswordExpired(Credential.java:82)

                at com.verifone.isd.client.eSMSTest.testisPasswordExpired(eSMSTest.java:27)

                at com.verifone.isd.client.__eSMSTest_unitTestImpl.doRunTest(__eSMSTest_unitTestImpl.java:10)

                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:389)

                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:287)

                at com.google.gwt.http.client.RequestBuilder$1.onReadyStateChange(RequestBuilder.java:395)

                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

                at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

                at java.lang.reflect.Method.invoke(Method.java:597)

                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:167)

                at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:326)

                at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:207)

                at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:132)

                at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:561)

                at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:269)

                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:221)

                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

                at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

                at java.lang.reflect.Method.invoke(Method.java:597)

                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:167)

                at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:281)

                at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:531)

                at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:352)

                at java.lang.Thread.run(Thread.java:662)

 

+Raja
Thanks,
Raja

Alex Dobjanschi

unread,
Aug 18, 2011, 6:55:39 AM8/18/11
to google-we...@googlegroups.com
One thing you should know about unit testing the client code (gwt) of your project is that it's very very slow. See more here.

If you're new to unit testing (or only junit?), then I'd recommend writing some tests for a pure java app (perhaps your server code). Not only it's 1-2 seconds fast, but it also gives you valuable knowledge (besides learning, you will suddenly discover object dependencies and possible problems, how to generate objects using factories, how to wire them, how to start test-driven development).

Specifically for TDD, here's an example: 
imagine you write a post-it app, that shares messages between users. Your client code should not allow an empty post-it to be sent to server code, but your server code should also handle the case of empty message (either throw an exception, log the message, ignore, etc). Having a test that ensures this correct behavior will save you plenty of time before ever sending any byte through the wire.
Hope that made any sense,
Alex D. 
Reply all
Reply to author
Forward
0 new messages