GWT:在模块中找不到测试类'com.myco.clearing.commons.xml.XMLNodeTest'

时间:2011-11-16 14:59:31

标签: gwt maven junit gwttestcase

我有一个Maven(3.0.3)/ GWT(2.4)项目。我正在尝试编写一些JUnit测试用例但遇到问题。我的所有测试用例都扩展了GWTTestCase并包含了这段代码......

@Override
public String getModuleName() {
    return "com.myco.clearing.product.ProductPlus";
}

“ProductPlus.gwt.xml”文件位于我的src / main / java目录中。要在我的类路径中包含它,我已将此配置为我的surefire-plugin ...

        <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>

然而,在运行“mvn clean test”时,我得到了所有这些错误,包括这个......

testParsingNodeWithAttributes(com.myco.clearing.commons.xml.XMLNodeTest)  Time elapsed: 2.563 sec  <<< ERROR!
com.google.gwt.junit.JUnitFatalLaunchException: The test class 'com.myco.clearing.commons.xml.XMLNodeTest' was not found in module 'com.myco.clearing.product.ProductPlus'; no compilation unit for that type was seen
at com.google.gwt.junit.JUnitShell.checkTestClassInCurrentModule(JUnitShell.java:743)
at com.google.gwt.junit.JUnitShell.runTestImpl(JUnitShell.java:1346)
at com.google.gwt.junit.JUnitShell.runTestImpl(JUnitShell.java:1309)
at com.google.gwt.junit.JUnitShell.runTest(JUnitShell.java:653)
at com.google.gwt.junit.client.GWTTestCase.runTest(GWTTestCase.java:441)
at junit.framework.TestCase.runBare(TestCase.java:134)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:124)
at com.google.gwt.junit.client.GWTTestCase.run(GWTTestCase.java:296)
at junit.framework.TestSuite.runTest(TestSuite.java:232)
at junit.framework.TestSuite.run(TestSuite.java:227)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:83)
at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:59)
at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:120)
at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:145)
at org.apache.maven.surefire.Surefire.run(Surefire.java:104)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:290)
at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:1017)

这是一个奇怪的错误,因为有问题的类在我的src / test / java目录中,我将其作为“additionalClassPathElement”(上图)包含在内。我需要做出哪些其他配置来纠正此错误? - 戴夫

1 个答案:

答案 0 :(得分:1)

测试包必须位于指定模块的客户端类路径中。根据模块的名称,您的测试可能属于com.myco.clearing.product.client包或其子包。