我有一个使用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生命周期中,测试阶段被定义为在integration-test之前存在,没有办法跳过测试阶段来运行纯粹的integration-test?
由于我将所有的测试代码混在了/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测试?