Unittesting AsyncTaskLoader with getLoaderResultSynchronously

I am trying to create unit tests for a REST client that makes some API calls. The client works fine in a direct application, but I cannot get it to work in a test case.

Obviously, LoaderTestCase.getLoaderResultSynchronously () can be used here (at least according to the Android link, but it does not accept my bootloader. Code:

public void testGetEventInfo() {
    // Init some vars
    ...

    // Create & execute loader
    RESTLoader loader = new RESTLoader(getContext(),
            RESTLoader.HTTPVerb.GET, action, params, LOADER_GET_NEWS);
    getLoaderResultSynchronously(loader);
}

This leads to an error getLoaderResultSynchronously (Loader) in type LoaderTestCase is not applicable for arguments (RESTLoader).

RESTLoader extends AsyncLoader. Please note that I use the support library, maybe the bootloader is not compatible there? The documentation does not provide information about this.

I tried to solve this in several ways, although none of them work:

  • .
  • CountdownLatch ( ). , - / .
  • () .
  • SO, .

- , getLoaderResultSynchronously ? , ? , .

,

+5
3

? :

import android.content.Loader;
import android.content.Loader.OnLoadCompleteListener;

, Android LoaderTestCase. - LoaderManager (.. android.content.Loader), . , LoaderManager . Loader, , .

+6

LoaderTestCase , SupportLoaderTestCase (, android.content.Loader android.support.v4.content.Loader). SupportLoaderTestCase ( LoaderTestCase)

+3

, (getLoaderResultSynchronously), android.content.Loader. RESTLoader EXACT, . , android.support.v4.content.Loader, .

LoaderTestCase, .

0

All Articles