Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    JUnit testing client side code with datasource

    I am using gwt 2.3 and smartclient 2.5 nightly and eclipse 3.6.2. I am currently trying to unit test my client side code. I've got the unit test running but it fails b/c of a null pointer exception when it hits the line:
    Code:
    String []array = theListGridDataSource.getFieldNames();
    In the line before it I set the datasource by calling DataSource.get(aName); but that returns null. aName is a string that represents the ds.xml file I have under /war/ds. What do I need to do to get the datasources available to me for my tests? The way I am running my tests is by right clicking on the test and selecting run as gwt junit test.
    Code:
    java.lang.RuntimeException: Remote test failed at 10.4.1.140 / 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:127)
    	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:118)
    	at com.google.gwt.junit.client.GWTTestCase.run(GWTTestCase.java:296)
    	at junit.framework.TestSuite.runTest(TestSuite.java:208)
    	at junit.framework.TestSuite.run(TestSuite.java:203)
    	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.NullPointerException
    	at my.package.client.ui.Page.setListGridProperties(Page.java:277)
    	at my.package.client.ui.MyClassPage.<init>(MyClassPage.java:57)
    	at my.package.client.ui.MyClassPageTest.testMyClassPage(MyClassPageTest.java:61)
    	at my.package.client.ui.__MyClassPageTest_unitTestImpl.doRunTest(__MyClassPageTest_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: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)

    #2
    If you know what set of DataSources are going to be required by your application, you can modify the HTML bootstrap file for the application to include a 'script src=' tag that loads the dataSource via the DataSourceLoader servlet. Something like this:

    Code:
        <script src="builtinds/sc/DataSourceLoader?dataSource=supplyItem,animals,employees"></script>
    This ensures the dataSource(s) are loaded in the application code when the page is loaded, so get() will not need to perform an asynchronous fetch.

    Comment


      #3
      Originally posted by Isomorphic
      If you know what set of DataSources are going to be required by your application, you can modify the HTML bootstrap file for the application to include a 'script src=' tag that loads the dataSource via the DataSourceLoader servlet. Something like this:

      Code:
          <script src="builtinds/sc/DataSourceLoader?dataSource=supplyItem,animals,employees"></script>
      This ensures the dataSource(s) are loaded in the application code when the page is loaded, so get() will not need to perform an asynchronous fetch.
      I have this code in my html file already. It doesn't work. Is there some code I need to put in my test case? Right now all I do is implement getModuleName that returns the module name and I construct one of my classes.
      Code:
      public String getModuleName()
      {
      return "my.Module";
      }
      
      public testMyClass()
      {
      MyClass object = new MyClass();
      assertSame("MyClass", object.name, "Message");
      }
      In the html file:
      Code:
      <script src="mymodule/sc/DataSourceLoader?dataSource=MyDataSource"></script>

      Comment


        #4
        Sorry, we missed that you were trying to use GWTTestCase - this basically won't work, it's not a real browser (it's HTMLUnit instead) and it also has some limitations around compiler add-ons. Instead, use our Selenium support with Selenium RC to construct runnable test cases. This also has the advantage that the tests run in real browsers.

        Comment

        Working...
        X