GWTTestSuite - ClassCastException on executing test suite

71 views
Skip to first unread message

Jan

unread,
Oct 14, 2008, 7:44:18 AM10/14/08
to Google Web Toolkit
Hello,

I created a module containing GWTTestCases as described here (I am
using GWT 1.5.2 on Windows XP):

http://code.google.com/docreader/#p=google-web-toolkit-doc-1-5&s=google-web-toolkit-doc-1-5&t=DevGuideJUnitSuites

and here

http://60-248-16-66.hinet-ip.hinet.net/GWT/doc/html/com.google.gwt.doc.DeveloperGuide.JUnitIntegration.html

I have one GWTTestCase class and one GWTTestSuite class. Here is the
code:

8< - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

package test.client;

import junit.framework.Test;
import junit.framework.TestSuite;

import com.google.gwt.junit.tools.GWTTestSuite;

public class TestTestSuite extends GWTTestSuite {

public static Test suite() {
TestSuite suite = new TestSuite("Tests");
suite.addTestSuite(TestTest.class);
return suite;
}

}

---

package test.client;

import com.google.gwt.junit.client.GWTTestCase;

public class TestTest extends GWTTestCase {

@Override
public String getModuleName() {
return "test.Test";
}

public void testStuff() {
assertTrue(2 + 2 == 4);
}

}


>8 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

And here is the Module xml:

<module>

<inherits name='com.google.gwt.junit.JUnit'/>

</module>

Invoking the test case using the following command line works:

@java -Dgwt.args="-out www-test" -Xmx256M -cp ".\src;.\bin;.\lib
\junit.jar;.\lib\gwt-user.jar;.\lib\gwt-dev-windows.jar"
junit.textui.TestRunner test.client.TestTest %*

Invoking the TestTestSuite using the following command line:

@java -Dgwt.args="-out www-test" -Xmx256M -cp ".\src;.\bin;.\lib
\junit.jar;.\lib\gwt-user.jar;.\lib\gwt-dev-windows.jar"
junit.textui.TestRunner test.client.TestTestSuite %*

fails with the error message:

Error: java.lang.ClassCastException: class test.client.TestTestSuite

I checked the class path several times. All src folders and jars are
present.

I played around with the code a bit. Letting the TestTestSuite class
inherit from GWTTestCase works (to some extend). Here is the changed
code:

package test.client;

import junit.framework.Test;

import com.google.gwt.junit.client.GWTTestCase;
import com.google.gwt.junit.tools.GWTTestSuite;

public class TestTestSuite extends GWTTestCase {


@Override
public String getModuleName() {
return "test.Test";
}

public static Test suite() {
GWTTestSuite suite = new GWTTestSuite("Tests");
suite.addTestSuite(TestTest.class);
return suite;
}

}


Now the test case is run. However, the GWT compiler complains with
some error messages:

Removing units with errors
[ERROR] Errors in 'file:/<path goes here>/src/test/client/
TestTestSuite.java'
[ERROR] Line 17: No source code is available for type
com.google.gwt.junit.tools.GWTTestSuite; did you forget to inherit a
required module?

I have no idea which module could be missing.

Any ideas from the GWT experts?

Cheers,

Jan





sean

unread,
Oct 23, 2008, 3:23:13 PM10/23/08
to Google Web Toolkit
Hi Jan,

I also receive the "No source code is available for type
com.google.gwt.junit.tools.GWTTestSuite; did you forget to inherit a
required module? " message. I think this must be something GWT just
left out. One would think you would find the module for GWTTestSuite,
but it does not exist. However, the functionality still works for me
(all test classes get run). So the errors are thrown but don't seem to
matter. Kind of annoying.

On Oct 14, 4:44 am, Jan <jan.karst...@googlemail.com> wrote:
> Hello,
>
> I created a module containing GWTTestCases as described here (I am
> using GWT 1.5.2 on Windows XP):
>
> http://code.google.com/docreader/#p=google-web-toolkit-doc-1-5&s=goog...
>
> and here
>
> http://60-248-16-66.hinet-ip.hinet.net/GWT/doc/html/com.google.gwt.do...

JAWspeak

unread,
Oct 24, 2008, 4:41:42 AM10/24/08
to Google Web Toolkit
I will add my report to this as well. Seems like a bug, or oversight
in the error logging from GWT.

My test (which passes in isolation):
public class PackagePanelTest extends GWTTestCase {
public String getModuleName() {
return "com.xyzclient.web.App";
}

public void testShouldMakeAllFieldsAvailableWhenPopulated() throws
Exception {
Pkg pkg = new PackageBuilder("2008xxxx").build();
PackagePanel packagePanel = new PackagePanel();
packagePanel.populate(pkg);
}
}



My suite **Note how it differs from the instructions on the web. I
create a GWTTestSuite, not a TestSuite:

public class AllGwtTests extends GWTTestSuite {
public static Test suite() {
GWTTestSuite suite = new GWTTestSuite();
suite.addTestSuite(PackagePanelTest.class);
return suite;
}
}




My suite passes (when run in the IDE), but it has messages such as
this:
Compiling Java source files in module 'com.xyzclient.web.App.JUnit'
Removing units with errors
[ERROR] Errors in 'file:/Users/admin/projects/x/pr/test-gwt/com/
xyzclient/web/client/AllGwtTests.java'
[ERROR] Line 12: No source code is available for type
com.google.gwt.junit.tools.GWTTestSuite; did you forget to inherit a
required module?
Rebinding com.google.gwt.junit.client.impl.GWTRunner
Removing units with errors
[ERROR] Errors in 'file:/Users/admin/projects/x/pr/test-gwt/com/
xyzclient/web/client/AllGwtTests.java'
[ERROR] Line 12: No source code is available for type
com.google.gwt.junit.tools.GWTTestSuite; did you forget to inherit a
required module?


-Jonathan

Nicolas

unread,
Nov 20, 2008, 8:54:33 AM11/20/08
to Google Web Toolkit
Hi all,

Actually, GWTTestSuite is a Java helper class, not translated to
Javascript. Look at the package name : com.google.gwt.junit.tools
instead of com.google.gwt.junit.client for GWTTestCase (the last one
contains client).

Therefore, if your test suite is in the GWT compiler lookup path, GWT
compiler will try to translate it to Javascript (and will give you
error messages) but your test suite will still be launched.

As a workaround, you can put the following line in your .gwt.xml :
<source path="client" excludes="**/*TestSuite.java" />

A "cleaner" way would be to give the excludes arg at runtime and to
not pollute your module configuration, but I don't know if this is
possible.

Regards

Miles T.

unread,
Nov 20, 2008, 9:25:30 AM11/20/08
to Google Web Toolkit
Well... actually, you don't even need that... Just put your GWT test
suite class out of the client package.
Reply all
Reply to author
Forward
0 new messages