gwt-test-utils fails to run tests with Ant

758 views Asked by At

I've created a sample project to run my gwt tests with gwt-test-utils (https://github.com/povilasb/gwt-test-utils-sample). I'm using Ant (1.8.2) for builds, packages: gwt 2.6, juni 4.11 and gwt-test-utils 0.47.

Unfortunately I fail to run tests:

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 

It seems like someone already had this issue before: https://code.google.com/p/gwt-test-utils/issues/detail?id=168. Couldn't find the solution there.

Anyone had luck with gwt 2.6 and gwt-test-utils 4.7 and ant?

1

There are 1 answers

0
PovilasB On

I managed to solve my issue. I eliminated the error

Error while scanning package 'com.googlecode.gwt.test.internal.patchers'

By using fork mode in Ant junit task:

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

This is the recommended method to run junit tests:

In general, forking a new VM is recommended since it isolates your test from Ant's environment (which contains a lot of libraries on the classloader, in particular XML related classes) but it becomes really slow because of the big overhead associated with starting new Java VMs.

After this I had another error:

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

And I solved this error by adding source code directory to 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>

I guess gwt-test-utils needed sources of the gwt module. You can find fully working sample project on github.