我创建了一个示例项目,用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和蚂蚁?
答案 0 :(得分:1)
我设法解决了我的问题。我消除了错误
扫描软件包时出错&#39; com.googlecode.gwt.test.internal.patchers&#39;
在Ant
junit
任务中使用fork模式:
<junit haltonfailure="false" includeantruntime="false"
fork="yes" forkmode="once" >
这是运行junit
测试的recommended method:
一般情况下,建议分支新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
classpath:
<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上找到完整的示例项目。