0

I have a java library. I build it with Maven. I want to make sure it can be used by GWT users somewhere. I've added @GwtCompatible and @GwtIncompatible where appropriate. Now, I want to test that this will work as expected.

The library is a testing framework in Java (http://github.com/truth0/truth) - it provides various testing propositions, etc. People are going to use it in pure Java unit tests, but they are also going to use it in GWT integration tests (e.g. extends GWTTestCase). I don't myself have an application for this, but I need to validate that it won't break when used in GWT.

A normal JUnit test would (trivially) use the code like so:

import static ...Truth.ASSERT;

ASSERT.that(123456).isGreaterThan(12345);

I have created a small GWTTestCase that I wish to build on to fully exercise the GWT compatible subset of this library. The trivial GWTTestCase example goes like this:

import static org.truth.Truth.ASSERT
...
public class TruthGwtTest extends GWTTestCase {
  @Override public String getModuleName() {
    // I have a org/truth/TruthTest.gwt.xml file
    return "org.truth.TruthTest";
  }
  public void testFoo() {
    ASSERT.that(457923).is(1); // want this to fail
  }
}

My TruthTest.gwt.xml looks like this (and I admit I'm "cargo culting" a bit here)

<module>
  <source path=""/>
  <super-source path="super"/>
  <inherits name="com.google.gwt.junit.JUnit"/>
</module>

When I bind the gwt-maven-plugin with a "compile" and "test" execution, both executions properly bind and both run in the output. A little server is generated and run, but the test times out. When I inspect the content of the generated server, I see a lot of generated javascript, but I see no code that relates to the code I wrote in the test anywhere in the generated server.

I chose the value 457923 in the hopes that this magic number would be grep-able in the generated code, but I cannot find it. I'm just not sure, from docs, what I need to do to ensure that I have all the code properly GWT-compiling. I don't see any code I could relate back to the Truth framework itself, nor the GWTTestCase's test method.

Any experts out there in gwt-maven-plugin? Note - this isn't an app, it's a library - I just want to force the gwt compiler and a GwtTestCase to force the GWT infrastructure to validate that what I think will come out of it will come out of it. Do I need to run the maven-failsafe-plugin on a little test WAR plugin? Gaah.

Christian Gruber
  • 4,691
  • 1
  • 28
  • 28
  • What do you mean by `suitable` by GWT. What kind of code is it ? Server side ? GUI code ? JSNI code ? Give us more information on what are you trying to achieve. – Jean-Michel Garcia Aug 20 '12 at 14:03
  • Can you be more specific ? Can you post a small amount of code ? From what you have posted I cannot see where is the problem. What you mean by : `But when I set up a GwtTestCase that exercises that code, a little server is compiled and run, but I see no code that relates to the code I wrote` – Jean-Michel Garcia Aug 20 '12 at 14:33
  • Updated. Hopefully clearer - with code. – Christian Gruber Aug 20 '12 at 14:43

1 Answers1

0

Ok - I figured it out. The problem seemed to be that I wasn't specifying any browser emulation for htmlunit, and since there is no default browser, I needed to explicitly set it. Otherwise, it would simply start the server containing the unit-test, and expect you to connect a browser.

Christian Gruber
  • 4,691
  • 1
  • 28
  • 28