2

I've just switched to using CursorLoaders and I'm having trouble writing tests that utilize them. Since using the CursorLoader methodology takes the querying off of the main thread getInstrumentation().waitForIdleSync() is returning before the adapter is being updated (or at least this is my theory). I'm trying to avoid this is all my tests

public void testUpdateList() throws InvalidRecord, InterruptedException {
    ListView listView = frag.getListView();
    // Verify list is empty
    assertEquals(0, listView.getCount());

    // Add transaction directly into database
    transTable.addOccurrences(resolver, TestUtils.createMockTrans());

    //Don't want to do this but it works.   
    synchronized (this) {
        wait(500);
        assertEquals(1, listView.getCount());
    }
}

So my question is, is there a better way to test this functionality within the Android testing framework?

1 Answer 1

1

The solution I settled on was using the waitForCondition method within Robotium. Here is an example.

...
 // Waits for 500 milliseconds for the condition to be meet.  
 // If it isn't meet within this time limit the result is false.
 boolean isSatisfied =  solo.waitForCondition( new Condition() {
    public boolean isSatisfied() {
      return listView.getCount() == 1;
    }, 500);

  //Then I check if the condition has been meet.
  assertTrue(isSatisfied);
...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.