0

我创建了一个示例项目来使用 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 有好运吗?

4

1 回答 1

1

我设法解决了我的问题。我消除了错误

扫描包“com.googlecode.gwt.test.internal.patchers”时出错

Ant junit通过在任务中使用 fork 模式:

<junit haltonfailure="false" includeantruntime="false"
    fork="yes" forkmode="once" >

这是运行测试的推荐方法:junit

一般来说,建议使用 fork 一个新的 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上找到完整工作的示例项目。

于 2014-05-26T04:41:39.697 回答