JUnit Test on an Existing GWT Application

161 views
Skip to first unread message

Hongping Dai

unread,
Mar 14, 2007, 1:49:42 PM3/14/07
to Google-We...@googlegroups.com
I am trying to add JUnit test to an existing GWT application. The classes to be tested is in the path com.hpd.brax.client.

1. I added a path com.hpd.brax.test to store the junit test code
2. In Eclipse, click file-new-other... to add a JUnit Test Case: BRAXValueTestCase.java
3. Change the code to extends GWTTestCase:

///////////////////////////////////////////////

package com.hpd.brax.test;

import junit.framework.Assert;
import com.google.gwt.junit.client.GWTTestCase ;
import com.hpd.brax.client.BRAXValue;

public class BRAXValueTestCase extends GWTTestCase
{
    public String getModuleName()
    {
        return "BRAXValueTestCase.gwt.xml";
    }

    public void testInteger()
    {
        BRAXValue intNumber = BRAXValue.create(50);
        Assert.assertEquals(intNumber.toString(), "50");
        Assert.assertEquals(intNumber.typeName(), "Number");
    }
}

/////////////////////////////////////////////  

4. Create module file BRAXValueTestCase.gwt.xml in the same path

The module file is as follows:

//////////////////////////////////////

<module>
  <!-- Module com.biorad.brax.test.BRAXValueTestCase -->

  <!-- Standard inherit.                                           -->
  <inherits name='com.google.gwt.user.User '/>

</module>

///////////////////////////////////

When I right-click the test path to run as JUnit, I got the follwoing error in the console:

The development shell servlet received a request to generate a host page for module ' BRAXValueTestCase.gwt.xml'
   Loading module 'BRAXValueTestCase.gwt.xml'
      [ERROR] Unable to find 'BRAXValueTestCase/gwt/xml.gwt.xml' on your classpath; could be a typo, or maybe you forgot to include a classpath entry for source?

The Failure Trace has the following:

com.google.gwt.junit.client.TimeoutException: The browser did not contact the server within 20000ms.
    at com.google.gwt.junit.JUnitShell.notDone(JUnitShell.java:270)
    at com.google.gwt.dev.GWTShell.pumpEventLoop(GWTShell.java:585)
    at com.google.gwt.junit.JUnitShell.runTestImpl(JUnitShell.java:306)
    at com.google.gwt.junit.JUnitShell.runTest(JUnitShell.java:115)
    at com.google.gwt.junit.client.GWTTestCase.runTest(GWTTestCase.java:172)
    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:109)
    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 :128)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests (RemoteTestRunner.java:673)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)

I am newbie in this area. Your help is very much appreciated.





Dan Morrill

unread,
Mar 14, 2007, 9:44:43 PM3/14/07
to Google-We...@googlegroups.com

Hello!

The exception you posted is a very general one.  However, it usually means that the test module failed to compile.

You said that you added a com.hpd.brax.test package for your test cases.  Did you also add that package as a <source> tag in your .gwt.xml file?

You posted this as your .gwt.xml for your test module:
<module>

  <inherits name='com.google.gwt.user.User '/>
</module>

You may need to add a line like this:
<source path="test"/>

Finally, if your test module is testing code in your main package, you probably want to inherit your actual application's source code too.  You would do that with a line such as this one:
<inherits name="com.hpd.brax.YourApplicationName"/>

Your complete .gwt.xml file for the JUnit test module would look like this:
<module>
  <inherits name='com.google.gwt.user.User '/>
  <inherits name="com.hpd.brax.YourApplicationName"/>
  <source path="test"/>
</module>

Hope that helps!

- Dan Morrill

Hongping Dai

unread,
Mar 14, 2007, 11:53:37 PM3/14/07
to Google-We...@googlegroups.com
Hi, Dan,

    Thank you very much for your help. I added the two lines to the module file. However, almost the same problem came up:

    The development shell servlet received a request to generate a host page for module ' com.biorad.brax.test.BRAXValueTestCase.gwt.xml'
   Loading module 'com.brax.test.BRAXValueTestCase.gwt.xml'
      [ERROR] Unable to find 'com/brax/test/BRAXValueTestCase/gwt/xml.gwt.xml' on your classpath; could be a typo, or maybe you forgot to include a classpath entry for source?


And failure tree:


com.google.gwt.junit.client.TimeoutException: The browser did not contact the server within 20000ms.
    at com.google.gwt.junit.JUnitShell.notDone(JUnitShell.java:270)
    at com.google.gwt.dev.GWTShell.pumpEventLoop (GWTShell.java:585)

    at com.google.gwt.junit.JUnitShell.runTestImpl(JUnitShell.java:306)
    at com.google.gwt.junit.JUnitShell.runTest(JUnitShell.java:115)
    at com.google.gwt.junit.client.GWTTestCase.runTest (GWTTestCase.java:172)

    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:109)
    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:128)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run (TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)


By the way, the code to be tested in this case is a small part. I am thinking to create test case for each part of the whole application, and finally creating a test suite to run them all.

Any more suggestions or comments will be very much appreciated.

Best regards,

Hongping

dominik_steiner

unread,
Mar 15, 2007, 2:31:06 AM3/15/07
to Google Web Toolkit
Hi hongping,

I would suggest generating a basic test case using the
junitCreator.bat and using the standard convention. (putting your test
classes under com.foo.client.)

Have a look at this thread that might give you more details

http://groups.google.com/group/Google-Web-Toolkit/browse_thread/thread/ecb25ba44760c88c/b3a188dfa6de2418?lnk=gst&q=gwttestcase&rnum=1#b3a188dfa6de2418

HTH

Dominik

On 15 Mrz., 04:53, "Hongping Dai" <hongping....@gmail.com> wrote:
> Hi, Dan,
>
> Thank you very much for your help. I added the two lines to the module
> file. However, almost the same problem came up:
>
> The development shell servlet received a request to generate a host page
> for module 'com.biorad.brax.test.BRAXValueTestCase.gwt.xml'
> Loading module 'com.brax.test.BRAXValueTestCase.gwt.xml'
> [ERROR] Unable to find
> 'com/brax/test/BRAXValueTestCase/gwt/xml.gwt.xml' on your classpath; could
> be a typo, or maybe you forgot to include a classpath entry for source?
>
> And failure tree:
>
> com.google.gwt.junit.client.TimeoutException: The browser did not contact
> the server within 20000ms.
> at com.google.gwt.junit.JUnitShell.notDone(JUnitShell.java:270)

> at com.google.gwt.dev.GWTShell.pumpEventLoop(GWTShell.java:585)
> at com.google.gwt.junit.JUnitShell.runTestImpl(JUnitShell.java:306)
> at com.google.gwt.junit.JUnitShell.runTest(JUnitShell.java:115)
> at com.google.gwt.junit.client.GWTTestCase.runTest(GWTTestCase.java:172)
> 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:109)

> 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:128)
> at org.eclipse.jdt.internal.junit.runner.TestExecution.run(
> TestExecution.java:38)
> at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(

> RemoteTestRunner.java:460)
> at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(
> RemoteTestRunner.java:673)
> at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(
> RemoteTestRunner.java:386)
> at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(

> RemoteTestRunner.java:196)
>
> By the way, the code to be tested in this case is a small part. I am
> thinking to create test case for each part of the whole application, and
> finally creating a test suite to run them all.
>
> Any more suggestions or comments will be very much appreciated.
>
> Best regards,
>
> Hongping
>

> > > JUnit3TestReference.java :128)


> > > at org.eclipse.jdt.internal.junit.runner.TestExecution.run(
> > > TestExecution.java:38)
> > > at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(
> > > RemoteTestRunner.java:460)
> > > at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests (
> > > RemoteTestRunner.java:673)
> > > at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(
> > > RemoteTestRunner.java:386)
> > > at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(

Reply all
Reply to author
Forward
0 new messages