【发布时间】:2010-12-28 22:08:14
【问题描述】:
我在 Maven 中构建了一个 gwt 应用程序,现在我尝试运行一个简单的 GWT 测试,如下所示:
public class GwtTestLaughter extends GWTTestCase {
/**
* Specifies a module to use when running this test case. The returned
* module must include the source for this class.
*
* @see com.google.gwt.junit.client.GWTTestCase#getModuleName()
*/
@Override
public String getModuleName() {
return "com.sample.services.joker.laughter.Laughter";
}
/**
* Add as many tests as you like
*/
public void testSimple() {
assertTrue(true);
}
}
在 pom.xml 文件中,配置 gwt-maven-plugin 和 maven-surefire-plugin 如下:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>2.1.0-1</version>
<configuration>
<!-- Use the 'war' directory for GWT hosted mode -->
<output>${basedir}/war</output>
<webXml>${basedir}/war/WEB-INF/web.xml</webXml>
<runTarget>index.html</runTarget>
<!-- Make sure the GWT compiler uses Xerces -->
<extraJvmArgs>
-Dgwt.style=DETAILED -Xmx512M -Xss1024k -XX:MaxPermSize=128m -Djavax.xml.parsers.DocumentBuilderFactory=org.apache.xerces.jaxp.DocumentBuilderFactoryImpl -Djavax.xml.parsers.SAXParserFactory=org.apache.xerces.jaxp.SAXParserFactoryImpl -Dlogback.configurationFile=./src/test/resources/logback-test.xml
</extraJvmArgs>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>test</goal>
</goals>
</execution>
</executions>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<useFile>false</useFile>
<forkMode>once</forkMode>
<argLine>-Xmx128m</argLine>
<systemPropertyVariable>
<property>
<name>log4j.configuration</name>
<value>log4j.properties</value>
</property>
</systemPropertyVariables>
</configuration>
<executions>
<execution>
<id>unit-test</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<skip>false</skip>
<includes>
<include>**/*Test.java</include>
<includes>
<excludes>
<exclude>**/GwtTest*.java</exclude>
</excludes>
</configuration>
</execution>
<execution>
<id>integration-test</id>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<skip>true</skip>
<includes>
<include>**/GwtTest*.java</include>
<includes>
<excludes>
<exclude>**/*Test.java</exclude>
</excludes>
</configuration>
</execution>
<executions>
</plugin>
当我在命令行中运行“mvn test”时,我只能看到运行正常的 Junit 测试(带有 Test.java 文件名的测试),当我运行“mvn integration-test”时,我仍然看到所有测试,包括正常的 Junit 测试和 Gwt 测试(带有 GwtTest.java 文件名的测试)运行。
问题 1:
如何在集成测试期间完全排除运行正常的 Junit 测试?或者那是不可能的?因为在默认的maven生命周期中,测试阶段被定义为在集成测试之前存在,所以没有办法跳过测试阶段来运行纯粹的集成测试?
由于我在 /src/test/java 文件夹下混合了所有测试代码,当我运行“mvn integration-test”并在命令行窗口中观察输出时,我看到了以下内容:
[INFO] running com.sample.services.joker.laughter.client.GwtTestLaughter
..
[INFO] Validating newly compiled units
[INFO] [ERROR] Errors in 'file:...src/test/java/com/sample/joker/laughter/client/file1Test.java'..
[INFO] [ERROR] Line 42: No source code is available for type...; did you forget to inherit a required module?
...
问题 2:
我不明白,gwt 测试是一个非常简单的测试,为什么它会验证一个不相关的 *Test.java 并搜索它的源代码。虽然最终通过测试成功构建,但我怎样才能摆脱那些讨厌的错误消息?
也许我应该忘记 gwt-mavin-plugin 并坚持使用经典的 Juint 测试?
【问题讨论】: