Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/377.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 无法使用ant运行GWTTestCase测试_Java_Gwt_Ant_Junit_Gwttestcase - Fatal编程技术网

Java 无法使用ant运行GWTTestCase测试

Java 无法使用ant运行GWTTestCase测试,java,gwt,ant,junit,gwttestcase,Java,Gwt,Ant,Junit,Gwttestcase,我根本无法成功运行gwtsetcase测试。我使用的是gwt2.6.1,junit4.11,ant1.8.2。我已经创建了一个示例 Ant target运行测试(这里可能有一些明显的问题): 你知道我做错了什么吗?我也尝试过JUnit3.8,但没有帮助。可能缺少*jar文件或版本不正确?好的,我设法用Ant运行了gwtsetcase测试。示例项目正在进行中 首先,我切换到了junittaskfork模式。正如上面所说 一般来说,建议分叉一个新的虚拟机,因为它将您的测试与Ant的环境隔离开来(在类

我根本无法成功运行
gwtsetcase
测试。我使用的是
gwt2.6.1
junit4.11
ant1.8.2
。我已经创建了一个示例

Ant target运行测试(这里可能有一些明显的问题):


你知道我做错了什么吗?我也尝试过JUnit3.8,但没有帮助。可能缺少
*jar
文件或版本不正确?

好的,我设法用
Ant
运行了
gwtsetcase
测试。示例项目正在进行中

首先,我切换到了
junit
taskfork模式。正如上面所说

一般来说,建议分叉一个新的虚拟机,因为它将您的测试与Ant的环境隔离开来(在类加载器上包含很多库,特别是与XML相关的类),但是由于启动新Java虚拟机的巨大开销,它变得非常慢

然后,当我添加
验证api
包(
ivy.XML
)时,在处理XML时,我设法得到了比这个
[ERROR]意外错误更多的详细错误:

最后,我不得不将测试模块路径添加到测试类路径(
build.xml
):


...
...
...
<target name="test.gwt" depends="javac.test"
    description="Run GWTTestCase tests." >
    <junit haltonfailure="false" includeantruntime="false">
        <sysproperty key="gwt.args" value="-prod -runStyle
            HtmlUnit" />
        <sysproperty key="gwt.persistentunitcachedir"
            value="${gwt.cache.dir}" />

        <classpath>
            <pathelement location="${src.dir}" />
            <pathelement location="${test.build.dir}" />
            <path refid="project.class.path" />
        </classpath>
        <formatter type="brief" usefile="false" />

        <test name="com.example.client.TestPerson" />
    </junit>
</target>
test.gwt:
    [junit] Testsuite: com.example.client.TestPerson
    [junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0.848 sec
    [junit]
    [junit] ------------- Standard Output ---------------
    [junit] Loading inherited module 'com.example.Main'
    [junit]    [ERROR] Unexpected error while processing XML
    [junit] java.lang.ClassCastException: org.apache.xerces.parsers.XIncludeAwareParserConfiguration cannot be cast to org.apache.xerces.xni.parser.XMLParserConfiguration
    [junit]     at org.apache.xerces.parsers.SAXParser.<init>(Unknown Source)
    [junit]     at org.apache.xerces.parsers.SAXParser.<init>(Unknown Source)
    [junit]     at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.<init>(Unknown Source)
    [junit]     at org.apache.xerces.jaxp.SAXParserImpl.<init>(Unknown Source)
    [junit]     at org.apache.xerces.jaxp.SAXParserFactoryImpl.newSAXParser(Unknown Source)
    [junit]     at com.google.gwt.dev.util.xml.ReflectiveParser.createNewSaxParser(ReflectiveParser.java:65)
    [junit]     at com.google.gwt.dev.util.xml.ReflectiveParser.access$000(ReflectiveParser.java:46)
    [junit]     at com.google.gwt.dev.util.xml.ReflectiveParser$Impl.parse(ReflectiveParser.java:343)
    [junit]     at com.google.gwt.dev.util.xml.ReflectiveParser$Impl.access$200(ReflectiveParser.java:68)
    [junit]     at com.google.gwt.dev.util.xml.ReflectiveParser.parse(ReflectiveParser.java:418)
    [junit]     at com.google.gwt.dev.cfg.ModuleDefLoader.nestedLoad(ModuleDefLoader.java:333)
    [junit]     at com.google.gwt.dev.cfg.ModuleDefLoader$1.load(ModuleDefLoader.java:100)
    [junit]     at com.google.gwt.dev.cfg.ModuleDefLoader.doLoadModule(ModuleDefLoader.java:197)
    [junit]     at com.google.gwt.dev.cfg.ModuleDefLoader.doLoadModule(ModuleDefLoader.java:176)
    [junit]     at com.google.gwt.dev.cfg.ModuleDefLoader.createSyntheticModule(ModuleDefLoader.java:105)
    [junit]     at com.google.gwt.junit.CompileStrategy.maybeCompileModuleImpl2(CompileStrategy.java:165)
    [junit]     at com.google.gwt.junit.CompileStrategy.maybeCompileModuleImpl(CompileStrategy.java:112)
    [junit]     at com.google.gwt.junit.SimpleCompileStrategy.maybeCompileModule(SimpleCompileStrategy.java:36)
    [junit]     at com.google.gwt.junit.JUnitShell.runTestImpl(JUnitShell.java:1342)
    [junit]     at com.google.gwt.junit.JUnitShell.runTestImpl(JUnitShell.java:1311)
    [junit]     at com.google.gwt.junit.JUnitShell.runTest(JUnitShell.java:705)
    [junit]     at com.google.gwt.junit.client.GWTTestCase.runTest(GWTTestCase.java:421)
    [junit]     at junit.framework.TestCase.runBare(TestCase.java:130)
    [junit]     at junit.framework.TestResult$1.protect(TestResult.java:106)
    [junit]     at junit.framework.TestResult.runProtected(TestResult.java:124)
    [junit]     at junit.framework.TestResult.run(TestResult.java:109)
    [junit]     at junit.framework.TestCase.run(TestCase.java:120)
    [junit]     at com.google.gwt.junit.client.GWTTestCase.run(GWTTestCase.java:247)
    [junit]     at junit.framework.TestSuite.runTest(TestSuite.java:230)
    [junit]     at junit.framework.TestSuite.run(TestSuite.java:225)
    [junit]     at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:518)
    [junit]     at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.executeInVM(JUnitTask.java:1420)
    [junit]     at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.execute(JUnitTask.java:848)
    [junit]     at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.executeOrQueue(JUnitTask.java:1899)
    [junit]     at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.execute(JUnitTask.java:800)
    [junit]     at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
    [junit]     at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
    [junit]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    [junit]     at java.lang.reflect.Method.invoke(Method.java:616)
    [junit]     at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
    [junit]     at org.apache.tools.ant.Task.perform(Task.java:348)
    [junit]     at org.apache.tools.ant.Target.execute(Target.java:390)
    [junit]     at org.apache.tools.ant.Target.performTasks(Target.java:411)
    [junit]     at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
    [junit]     at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
    [junit]     at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
    [junit]     at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
    [junit]     at org.apache.tools.ant.Main.runBuild(Main.java:809)
    [junit]     at org.apache.tools.ant.Main.startAnt(Main.java:217)
    [junit]     at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
    [junit]     at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)
    [junit] ------------- ---------------- ---------------
    [junit] Testcase: testCreate(com.example.client.TestPerson):    Caused an ERROR
    [junit] (see previous log entries)
    [junit] com.google.gwt.core.ext.UnableToCompleteException: (see previous log entries)
    [junit]     at com.google.gwt.dev.cfg.ModuleDefLoader.nestedLoad(ModuleDefLoader.java:336)
    [junit]     at com.google.gwt.dev.cfg.ModuleDefLoader$1.load(ModuleDefLoader.java:100)
    [junit]     at com.google.gwt.dev.cfg.ModuleDefLoader.doLoadModule(ModuleDefLoader.java:197)
    [junit]     at com.google.gwt.dev.cfg.ModuleDefLoader.doLoadModule(ModuleDefLoader.java:176)
    [junit]     at com.google.gwt.dev.cfg.ModuleDefLoader.createSyntheticModule(ModuleDefLoader.java:105)
    [junit]     at com.google.gwt.junit.CompileStrategy.maybeCompileModuleImpl2(CompileStrategy.java:165)
    [junit]     at com.google.gwt.junit.CompileStrategy.maybeCompileModuleImpl(CompileStrategy.java:112)
    [junit]     at com.google.gwt.junit.SimpleCompileStrategy.maybeCompileModule(SimpleCompileStrategy.java:36)
    [junit]     at com.google.gwt.junit.JUnitShell.runTestImpl(JUnitShell.java:1342)
    [junit]     at com.google.gwt.junit.JUnitShell.runTestImpl(JUnitShell.java:1311)
    [junit]     at com.google.gwt.junit.JUnitShell.runTest(JUnitShell.java:705)
    [junit]     at com.google.gwt.junit.client.GWTTestCase.runTest(GWTTestCase.java:421)
    [junit]     at com.google.gwt.junit.client.GWTTestCase.run(GWTTestCase.java:247)
    [junit]
    [junit]
    [junit] Test com.example.client.TestPerson FAILED

BUILD SUCCESSFUL
Total time: 1 second
<dependency org="javax.validation" name="validation-api" rev="1.0.0.GA" />
<module rename-to="MainTests" >
    <inherits name="com.example.Main" />
    <source path="client" />
</module>
<property name="test.src.dir" value="test" />
...
<junit haltonfailure="false" includeantruntime="false"
    fork="true" forkmode="once" >

    <classpath>
        ...
        <pathelement location="${test.src.dir}" />
        ...
    </classpath>
</junit>