I am writing an Android Activity test case by extending ActivityInstrumentationTestCase2. The Activity I am testing offloads work to a Loader. The Activity itself is the LoaderCallback.
The problem is that the test case finishes before the Loader completes its work (because the Loader is obviously running on another thread than the test case). How can I get the test case to wait until the Loader has finished its work.
One thought I had was to join to the underlying Loader thread. However, I can’t seem to find a way to get access to the underlying thread. Also, the Loader thread might not start immediately so not sure this is the right approach.
The other though I had was to register a LoaderListener in the test case, but it seems a particular Loader can only have one LoaderListener.
You could set a max timeout. Check for a null value in the loader every so often until you reach the max timeout. Once the max timeout is set have the test fail because the loader would not load.