JUnit-Testing and GAE APIs

Some issues I encountered when testing a new Java library for loading multiple URLs in parallel on the Google Apps Engine (GAE) (more about that library in another post).

Here are some of the typical errors you might encounter:

Missing timeout class

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

Context menu on project: Properties -> 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 within a package that is configured in the module file (*.gwt.xml). You should create a new source folder (Context menu on project -> New -> Source Folder) and create the whole package structure you use within 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 later on.
  • If you are testing client-side code, your test class needs implement GWTUnit *and* be run as GWTUnitTest *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 environment has not been initialized.

  • Set up the required libraries for testing:
    • Context menu on project -> Properties -> Build Path -> Libraries -> Add Variable -> Configure Variables -> 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 previous 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 following 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 available for testing and replace LocalURLFetchServiceTestConfig with the one you need.

I tried to keep it as brief as possible, for more details have a look at this page.

5 Replies to “JUnit-Testing and GAE APIs”

  1. This was helpful.
    I received the error:
    com.google.apphosting.api.ApiProxy$CallNotFoundException: The API package ‘file’ or call ‘Create()’ was not found.

    … and the reason why I post this here is (obviously) so that others may find it as well.

    Thanks a lot!

    1. Hi Konqi,

      Thanks for your comment. If I got it right, you found another typical error when running a test using JUnit, correct? What is the solution/fix to the error you describe? I will then add error+fix to the post (quoting you of course).

  2. This was helpful.
    I received the error:
    com.google.apphosting.api.ApiProxy$CallNotFoundException: The API package ‘file’ or call ‘Create()’ was not found.

    … and the reason why I post this here is (obviously) so that others may find it as well.

    Thanks a lot!

    1. Hi Konqi,

      Thanks for your comment. If I got it right, you found another typical error when running a test using JUnit, correct? What is the solution/fix to the error you describe? I will then add error+fix to the post (quoting you of course).

Leave a Reply

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