使用 Maven 运行 GWTTestCase
Running GWTTestCase with Maven
在运行 $mvn clean install 时,我无法使用我的 GWT 库项目运行 GWT 测试,它会抛出此错误:
[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')
但是应用程序在 App.gwt.xml
文件中有:
<?xml version="1.0" encoding="UTF-8"?>
<module>
<inherits name="com.google.gwt.core.Core" />
<inherits name='com.google.gwt.user.User'/>
<inherits name="com.google.gwt.i18n.I18N"/>
<inherits name="org.restlet.Restlet" />
<!-- Specify the paths for translatable code -->
<source path='client'/>
<source path='shared'/>
</module>
而且测试代码非常简单:
public class AppTest extends GWTTestCase {
@Before
public void prepareTests(){
}
@After
public void afterTests() {
}
@Override
public String getModuleName() {
return "com.mycompany.App";
}
@Test
public void test(){
Assert.assertTrue(true);
}
}
阻止测试运行的问题可能是什么?
1.- 不要使用 Junit-4,而是使用 Junit-3,删除 @Test
并使用 test
前缀
命名您的测试
2.- 覆盖 getModuleName 返回你的 gwt 模块
3.- 使用 gwtSetup
和 gwtTearDown
代替 @Before
和 @After
public class MyGwtTest extends GWTTestCase {
@Override
public String getModuleName() {
return "com.example.MyApp";
}
@Override
protected void gwtSetUp() throws Exception {
}
@Override
protected void gwtTearDown() throws Exception {
}
public void testSomething() {
// test something
}
}
4.- 适当配置 gwt-maven,以便您可以使用 mvn gwt:test
来 运行 您的测试
5.- 或者用这个 surefire 配置来配置你的 maven 项目,你可以使用正常的方式 mvn test
.
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.8.1</version>
<configuration>
<additionalClasspathElements>
<additionalClasspathElement>${project.build.sourceDirectory}</additionalClasspathElement>
<additionalClasspathElement>${project.build.testSourceDirectory}</additionalClasspathElement>
</additionalClasspathElements>
<useManifestOnlyJar>false</useManifestOnlyJar>
<forkMode>always</forkMode>
</configuration>
</plugin>
在运行 $mvn clean install 时,我无法使用我的 GWT 库项目运行 GWT 测试,它会抛出此错误:
[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')
但是应用程序在 App.gwt.xml
文件中有:
<?xml version="1.0" encoding="UTF-8"?>
<module>
<inherits name="com.google.gwt.core.Core" />
<inherits name='com.google.gwt.user.User'/>
<inherits name="com.google.gwt.i18n.I18N"/>
<inherits name="org.restlet.Restlet" />
<!-- Specify the paths for translatable code -->
<source path='client'/>
<source path='shared'/>
</module>
而且测试代码非常简单:
public class AppTest extends GWTTestCase {
@Before
public void prepareTests(){
}
@After
public void afterTests() {
}
@Override
public String getModuleName() {
return "com.mycompany.App";
}
@Test
public void test(){
Assert.assertTrue(true);
}
}
阻止测试运行的问题可能是什么?
1.- 不要使用 Junit-4,而是使用 Junit-3,删除 @Test
并使用 test
前缀
2.- 覆盖 getModuleName 返回你的 gwt 模块
3.- 使用 gwtSetup
和 gwtTearDown
代替 @Before
和 @After
public class MyGwtTest extends GWTTestCase {
@Override
public String getModuleName() {
return "com.example.MyApp";
}
@Override
protected void gwtSetUp() throws Exception {
}
@Override
protected void gwtTearDown() throws Exception {
}
public void testSomething() {
// test something
}
}
4.- 适当配置 gwt-maven,以便您可以使用 mvn gwt:test
来 运行 您的测试
5.- 或者用这个 surefire 配置来配置你的 maven 项目,你可以使用正常的方式 mvn test
.
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.8.1</version>
<configuration>
<additionalClasspathElements>
<additionalClasspathElement>${project.build.sourceDirectory}</additionalClasspathElement>
<additionalClasspathElement>${project.build.testSourceDirectory}</additionalClasspathElement>
</additionalClasspathElements>
<useManifestOnlyJar>false</useManifestOnlyJar>
<forkMode>always</forkMode>
</configuration>
</plugin>