JUnit-Testing and GAE APIs

Some issues I encoun­tered when test­ing a new Java library for load­ing mul­ti­ple URLs in par­al­lel on the Google Apps Engine (GAE) (more about that library in anoth­er post).

Here are some of the typ­i­cal errors you might encoun­ter:

Missing timeout class

java.lang.NoSuchMethodError: org.mortbay.thread.Timeout

Con­text menu on project: Prop­er­ties -> Build Path -> Order and Export: move GWT SDK *above* App Engine SDK (cf. here)

Compilation unit was not seen

com.google.gwt.junit.JUnitFatalLaunchException: The test class 'com.test.client.MyTest' was not found in module 'com.text.Module'; no compilation unit for that type was seen

  • The test class needs to be with­in a pack­age that is con­fig­ured in the mod­ule file (*.gwt.xml). You should cre­ate a new source fold­er (Con­text menu on project -> New -> Source Fold­er) and cre­ate the whole pack­age struc­ture you use with­in your project up to client, e.g. com.company.client, and put your GWT tests in it. This way you make sure that the tests are not going to be deployed to GAE lat­er on.
  • If you are test­ing client-side code, your test class needs imple­ment GWTU­nit *and* be run as GWTU­nitTest *not* as JUnitTest 😉

API package not found

java.util.concurrent.ExecutionException: com.google.apphosting.api.ApiProxy$CallNotFoundException: The API package 'urlfetch' or call 'Fetch()' was not found.

The GAE envi­ron­ment has not been ini­tial­ized.

  • Set up the required libraries for test­ing:
    • Con­text menu on project -> Prop­er­ties -> Build Path -> Libraries -> Add Vari­able -> Con­fig­ure Vari­ables -> New…: Set “SDK_ROOT” as name and search you disk for “appengine-api-stubs.jar” and copy the part before “/lib/impl” into the text box named “Path”
    • Select “SDK_ROOT” from the pre­vi­ous dialog, click “Extend…”, unfold lib and impl and select “…labs.jar”, “…stubs.jar”, and “…api.jar”; unfold “lib/testing” and select “…testing.jar” — done, whew.
  • Add fol­low­ing lines to your test class:
    private final LocalServiceTestHelper helper = new LocalServiceTestHelper(new LocalURLFetchServiceTestConfig());
    @Before public void setUp() { helper.setUp(); }
    @After public void tearDown() { helper.tearDown(); }
  • Have a look in com.google.appengine.tools.development.testing to see all the services/APIs avail­able for test­ing and replace LocalURLFetchServiceTestConfig with the one you need.

I tried to keep it as brief as pos­si­ble, for more details have a look at this page.

3 Replies to “JUnit-Testing and GAE APIs”

  1. This was help­ful.
    I received the error:
    com.google.apphosting.api.ApiProxy$CallNotFoundException: The API pack­age ‘file’ or call ‘Cre­ate()’ was not found.

    … and the rea­son why I post this here is (obvi­ous­ly) so that oth­ers may find it as well.

    Thanks a lot!

    1. Hi Kon­qi,

      Thanks for your com­ment. If I got it right, you found anoth­er typ­i­cal error when run­ning a test using JUnit, cor­rect? What is the solution/fix to the error you describe? I will then add error+fix to the post (quot­ing you of course).

Leave a Reply

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