使用maven gwt插件运行GWTTestCase时出错

Ale*_*x D 10 java gwt maven-2 unit-testing

我已经创建了一个扩展GWTTestCase的测试,但是我收到了这个错误:

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!
Run Code Online (Sandbox Code Playgroud)

GwtTestMyFirstTestCase.java位于/ src/test/java中,而GWT模块位于src/main/java中.我认为这应该不是问题.

我已根据http://mojo.codehaus.org/gwt-maven-plugin/user-guide/testing.html完成了所有要求,当然我的gwt模块已经间接地有com.google.gwt.core.Core进口.

<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">
<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>
Run Code Online (Sandbox Code Playgroud)

这是测试用例,位于/ src/test/java/com/myproject/test/ui中

public class GwtTestMyFirstTestCase extends GWTTestCase {

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

    public void testSomething() {


    }

}
Run Code Online (Sandbox Code Playgroud)

这是我正在尝试测试的gwt模块,位于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">
<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>
Run Code Online (Sandbox Code Playgroud)

任何人都可以给我一两个关于我做错的提示吗?

Jos*_*ust 9

重现KevinWong使用的解决方案来自maven-gwt-plugin doc,这对我来说在尝试其他解决方案失去了一个多小时之后起作用了.

<plugin>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.6</version>
    <configuration>
      <additionalClasspathElements>
        <additionalClasspathElement>${project.build.sourceDirectory}</additionalClasspathElement>
        <additionalClasspathElement>${project.build.testSourceDirectory}</additionalClasspathElement>
      </additionalClasspathElements>
      <useManifestOnlyJar>false</useManifestOnlyJar>
      <forkMode>always</forkMode>
      <systemProperties>
        <property>
          <name>gwt.args</name>
          <value>-out \${webAppDirectory}</value>
        </property>
      </systemProperties>
    </configuration>
  </plugin>
Run Code Online (Sandbox Code Playgroud)


mon*_*onj 6

我认为正确的做法只是将测试排除在你的maven生命周期之外.写这些是什么意思?你要做的是正确配置maven-surefire-plugin以使其工作.

你看,该插件使用系统类加载器来查找类,但GWTTestCase需要一个URLClassLoader.这就是你得到的原因[WARN] No source path entries; expect subsequent failures.和以下ClassNotFoundException.不过不用担心.很容易告诉maven使用URLClassLoader:

<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>
Run Code Online (Sandbox Code Playgroud)

请注意<userSystemClassLoader>false</useSystemClassLoader>条目.另外,请注意我添加了测试和主目录的源代码,以便允许GWT找到生成Javascript所需的类.您可能需要以不同方式配置它.


Ale*_*x D 5

问题是测试是通过surefire而不是gwt-maven插件运行的.我必须明确地从surefire插件中排除我的gwt测试:

<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> 
Run Code Online (Sandbox Code Playgroud)

我仍然无法运行我的GWTTestCase测试,但这是另一个问题并且还有另一个问题.我认为这个问题已经解决.