views:

373

answers:

3

I've created a test which extends GWTTestCase but I'm getting this error:

mvn integration-test gwt:test
...
Running com.myproject.test.ui.GwtTestMyFirstTestCase
Translatable source found in...                       
[WARN] No source path entries; expect subsequent failures
[ERROR] Unable to find type 'java.lang.Object'
[ERROR] Hint: Check that your module inherits 'com.google.gwt.core.Core' either directly or indirectly (most often by inheriting module 'com.google.gwt.user.User')
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 2.1 sec <<< FAILURE!

GwtTestMyFirstTestCase.java is in /src/test/java, while the GWT module is located in src/main/java. I assume this shouldn't be a problem.

I've done everything required according to http://mojo.codehaus.org/gwt-maven-plugin/user-guide/testing.html and of course that my gwt module already has com.google.gwt.core.Core indirectly imported.

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"&gt;
<modelVersion>4.0.0</modelVersion>
<groupId>com.myproject</groupId>
<artifactId>main</artifactId>
<packaging>jar</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>Main Module</name>

<properties>
    <gwt.module>com.myproject.MainModule</gwt.module>
</properties>

<parent>
    <groupId>com.myproject</groupId>
    <artifactId>app</artifactId>
    <version>0.1.0-SNAPSHOT</version>
</parent>

<dependencies>

    <dependency>
        <groupId>com.myproject</groupId>
        <artifactId>app-commons</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </dependency>

    <dependency>
        <groupId>com.google.gwt</groupId>
        <artifactId>gwt-dev</artifactId>
        <version>${gwt.version}</version>
        <scope>provided</scope>
    </dependency>


</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <configuration>
                <outputFile>../app/src/main/webapp/WEB-INF/main.tree</outputFile>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>gwt-maven-plugin</artifactId>


            <executions>
                    <execution>
                        <goals>
                            <goal>test</goal>
                        </goals>
                    </execution>
            </executions>

        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <configuration>
                <classesDirectory>
                    ${project.build.directory}/${project.build.finalName}/${gwt.module}
                </classesDirectory>
            </configuration>
        </plugin>
    </plugins>
</build>

</project>

Here is the test case, located in /src/test/java/com/myproject/test/ui

public class GwtTestMyFirstTestCase extends GWTTestCase {

    @Override
    public String getModuleName() {
        return "com.myproject.MainModule";
    }

    public void testSomething() {


    }

}

Here is the gwt module I'm trying to test, located in src/main/java/com/myproject/MainModule.gwt.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 1.7.1//EN" "http://google-web-toolkit.googlecode.com/svn/tags/1.7.1/distro-source/core/src/gwt-module.dtd"&gt;
<module>

    <inherits name='com.myproject.Commons' />

    <source path="site" />

    <source path="com.myproject.test.ui" />

    <set-property name="gwt.suppressNonStaticFinalFieldWarnings" value="true" />

    <entry-point class='com.myproject.site.SiteModuleEntry' />
</module>

Can anyone give me a hint or two about what I'm doing wrong?

A: 

I am very confident that this error has nothing to do with maven setup. My first guess would be that tests are not on gwt compile path... I guess the problematic source code is:

<source path="com.myproject.test.ui" />

try changing to:

<source path="com/myproject/test/ui" />

or whatever is the appropriate path.

markovuksanovic
A: 

The problem was that the test was run by surefire instead of gwt-maven plugin. I had to explicitly exclude my gwt tests from surefire plugin:

<plugin>
       <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>

            <configuration>
                <excludes>
                    <exclude>**/*GwtTest*.java</exclude>
                    <exclude>**/*Gwt*Suite*.java</exclude>
                </excludes>
            </configuration>
</plugin> 

I still can't run my GWTTestCase tests, but that's another problem and subject for another question. I consider this issue solved.

adancu
PLease mark an answer as being the right one, so the questions can be closed.
Romain Hippeau
A: 

I don't think the right thing to do is just to exclude the tests from your maven life cycle. What's the point of writen them? What you have to do is to properly configure the maven-surefire-plugin in order to make it work.

You see, that plugin uses a system classloader to look up the classes but GWTTestCase needs an URLClassLoader. That's the reason you are getting [WARN] No source path entries; expect subsequent failures. and the following ClassNotFoundException. No worries, though. It's easy to tell maven to use a URLClassLoader instead:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <configuration>
     <useSystemClassLoader>false</useSystemClassLoader>
     <additionalClasspathElements>
       <additionalClasspathElement>${basedir}/src/main/java</additionalClasspathElement>
       <additionalClasspathElement>${basedir}/src/test/java</additionalClasspathElement>
     </additionalClasspathElements>
  </configuration>
  <executions>
    <execution>
      <phase>integration-test</phase>
      <goals>
        <goal>test</goal>
      </goals>
    </execution>
   </executions>
</plugin>

Please, notice the <userSystemClassLoader>false</useSystemClassLoader> entry. Also, notice that I added the sources of my tests and main directories in order to allow GWT find the needed classes to generate the Javascript. You might need to configure it differently.

monzonj
I excluded the test clases from surefire plugin because I'm not using surefire plugin to run my tests. I'm using Maven Gwt Plugin for that. I tried to use surefire at some point but with no success. Maybe I'll try again to use surefire, but for now I'm staying with my current configuration. Thanks anyway for your answer.
adancu