UnsatisfiedLinkError: checkExtVer when unit testing gwt-ext

By | August 31, 2009

I ran into an issue while trying to test some innocent looking GWT-EXT code for a Google Web Toolkit app:

public void onActivate( com.gwtext.client.widgets.Panel panel )
if ( !( panel instanceof MyCustomGwtExtPanel ) )
throw new IllegalArgumentException( "Panel must be a MyCustomGwtPanel." );

… snip …

The test

I had one test to test that an exception is thrown:

@Test(expectedExceptions = IllegalArgumentException.class)
public void testOnActivate_unexpectedPanel()
Panel panel = new Panel();
new TripReportsPanelListener().onActivate( panel );

Test failures

It was so simple, I guess it just had to fail:

Caused by: java.lang.UnsupportedOperationException: ERROR: GWT.create() is only usable in client code! It cannot be called, for example, from server code. If you are running a unit test, check that your test case extends GWTTestCase and that GWT.create() is not called from within an initializer or constructor.
at com.google.gwt.core.client.GWT.create(GWT.java:85)
at com.google.gwt.user.client.ui.UIObject.(UIObject.java:140)
… 23 more

By using GWTMockUtilities.disarm in the setup and GWTMockUtilities.restore in the teardown, I made some progress by ended up with this error instead:

java.lang.UnsatisfiedLinkError: checkExtVer
at com.gwtext.client.widgets.Component.checkExtVer(Native Method)
at com.gwtext.client.widgets.Component.(Component.java:108)

The solution

The solution is right there in the stacktrace from Google.

I extended GWTTestCase but continued to get the same errors. The reason is simple enough, but has bitten me a a couple of times before. GWTTestCase is written using the old JUnit 3 style tests. My tests were using TestNG annotations which tells TestNG to run the tests as TestNG tests. Consequently the setup and teardown methods in GWTTestCase never get called. JUnit acts the same way if you mix and match JUnit 3 and 4 style test declarations.

It’s been a frustrating experience with UnsatisfiedLinkErrors and NoClassDefFoundErrors, but I eventually got what should be a simple unit test working. And it sucks that my seemingly innocent unit test have so many dependencies. It also stinks that GWT must be started up to run the tests resulting in a feedback loop increase of 10-15 seconds.

Leave a Reply

Your email address will not be published. Required fields are marked *