简体   繁体   中英

Testing a maven-built java library for suitability with GWT

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 (eg 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM