我创建了一个示例项目,使用gwt-test-utils (https://github.com/povilasb/gwt-test-utils-sample)运行gwt测试。我使用Ant(1.8.2)进行构建,包:gwt 2.6, juni 4.11和gwt-test-utils 0.47。
不幸的是,我无法运行测试:
html-test-utils-config:
test:
[junit] Testsuite: com.example.gwtTestUtils.client.PersonTest
[junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0.006 sec
[junit]
[junit] ------------- Standard Error -----------------
[junit] SLF4J: Failed to load class org.slf4j.impl.StaticLoggerBinder.
[junit] SLF4J: Defaulting to no-operation (NOP) logger implementation
[junit] ------------- ---------------- ---------------
[junit] Testcase: initializationError(com.example.gwtTestUtils.client.PersonTest): Caused an ERROR
[junit] Error while scanning package 'com.googlecode.gwt.test.internal.patchers'
[junit] com.googlecode.gwt.test.exceptions.GwtTestPatchException: Error while scanning package 'com.googlecode.gwt.test.internal.patchers'
[junit] at com.googlecode.gwt.test.internal.ClassesScanner.scanPackages(ClassesScanner.java:68)
[junit] at com.googlecode.gwt.test.internal.ConfigurationLoader.visitPatchClasses(ConfigurationLoader.java:291)
[junit] at com.googlecode.gwt.test.internal.ConfigurationLoader.<init>(ConfigurationLoader.java:65)
[junit] at com.googlecode.gwt.test.internal.GwtFactory.<init>(GwtFactory.java:91)
[junit] at com.googlecode.gwt.test.internal.GwtFactory.initializeIfNeeded(GwtFactory.java:46)
[junit] at com.googlecode.gwt.test.internal.junit.AbstractGwtRunner.<init>(AbstractGwtRunner.java:30)
[junit] at com.googlecode.gwt.test.GwtRunner.<init>(GwtRunner.java:19)
[junit] at java.lang.reflect.Constructor.newInstance(Constructor.java:532)
[junit] at java.lang.reflect.Constructor.newInstance(Constructor.java:532)
[junit] Caused by: com.googlecode.gwt.test.exceptions.GwtTestPatchException: Cannot find class in the classpath : 'com.googlecode.gwt.test.internal.patchers.AbstractHasDataPatcher'
[junit] at com.googlecode.gwt.test.internal.GwtClassPool.getClass(GwtClassPool.java:27)
[junit] at com.googlecode.gwt.test.internal.ClassesScanner.visitClass(ClassesScanner.java:107)
[junit] at com.googlecode.gwt.test.internal.ClassesScanner.scanClassesFromJarFile(ClassesScanner.java:99)
[junit] at com.googlecode.gwt.test.internal.ClassesScanner.scanPackages(ClassesScanner.java:62)
[junit]
[junit]
[junit] Test com.example.gwtTestUtils.client.PersonTest FAILED
BUILD SUCCESSFUL
Total time: 1 second
似乎有人之前已经遇到过这个问题:https://code.google.com/p/gwt-test-utils/issues/detail?id=168。在那里找不到解决办法。
有人使用gwt 2.6和gwt-test-utils 4.7和ant吗?
我设法解决了我的问题。我消除了错误
扫描'com. googlcode .gwt.test.internal.patchers'包时出错
在Ant
junit
中使用fork模式:
<junit haltonfailure="false" includeantruntime="false"
fork="yes" forkmode="once" >
这是运行junit
测试的推荐方法:
一般来说,推荐创建一个新的VM,因为它将您的测试从Ant的环境(在类加载器上包含许多库,特别是与XML相关的类)中隔离出来,但是由于启动新的Java VM相关的巨大开销,它变得非常慢。
在此之后,我又出现了一个错误:
test:
[junit] WARNING: multiple versions of ant detected in path for junit
[junit] jar:file:/usr/share/ant/lib/ant.jar!/org/apache/tools/ant/Project.class
[junit] and jar:file:/home/povilas/projects/gwt-test-utils-sample/lib/ant-1.8.2.jar!/org/apache/tools/ant/Project.class
[junit] Testsuite: com.example.gwtTestUtils.client.PersonTest
[junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0.005 sec
[junit]
[junit] ------------- Standard Error -----------------
[junit] SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
[junit] SLF4J: Defaulting to no-operation (NOP) logger implementation
[junit] SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
[junit] ------------- ---------------- ---------------
[junit] Testcase: initializationError(com.example.gwtTestUtils.client.PersonTest): Caused an ERROR
[junit] Error while generating gwt-test-utils prerequisites
[junit] com.googlecode.gwt.test.exceptions.GwtTestException: Error while generating gwt-test-utils prerequisites
[junit] at com.googlecode.gwt.test.internal.GwtFactory.<init>(GwtFactory.java:119)
[junit] at com.googlecode.gwt.test.internal.GwtFactory.initializeIfNeeded(GwtFactory.java:46)
[junit] at com.googlecode.gwt.test.internal.junit.AbstractGwtRunner.<init>(AbstractGwtRunner.java:30)
[junit] at com.googlecode.gwt.test.GwtRunner.<init>(GwtRunner.java:19)
[junit] at java.lang.reflect.Constructor.newInstance(Constructor.java:532)
[junit] at java.lang.reflect.Constructor.newInstance(Constructor.java:532)
[junit] Caused by: com.google.gwt.core.ext.UnableToCompleteException: (see previous log entries)
[junit] at com.google.gwt.dev.cfg.ModuleDefLoader.nestedLoad(ModuleDefLoader.java:315)
[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.googlecode.gwt.test.internal.GwtFactory.createModuleDef(GwtFactory.java:164)
[junit] at com.googlecode.gwt.test.internal.GwtFactory.<init>(GwtFactory.java:110)
[junit]
[junit]
[junit] Test com.example.gwtTestUtils.client.PersonTest FAILED
BUILD SUCCESSFUL
Total time: 1 second
我通过将源代码目录添加到junit
类路径来解决这个错误:
<property name="src.dir" value="src" />
...
<junit haltonfailure="false" includeantruntime="false"
fork="yes" forkmode="once" >
...
<classpath>
<path refid="project.class.path" />
<pathelement location="${test.build.dir}" />
<pathelement location="${src.dir}" />
</classpath>
...
</junit>
我猜gwt-test-utils需要gwt模块的源代码。你可以在github上找到完整的工作示例项目