2

CursorLoaders の使用に切り替えたばかりで、それらを使用するテストの作成に問題があります。CursorLoader 方法論を使用すると、メイン スレッドのクエリがオフになるためgetInstrumentation().waitForIdleSync()、アダプターが更新される前に返されます (少なくともこれは私の理論です)。これを回避しようとしているのはすべて私のテストです

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());
    }
}

私の質問は、Android テスト フレームワーク内でこの機能をテストするためのより良い方法はありますか?

4

1 に答える 1

1

私が解決した解決策は、waitForConditionRobotium 内のメソッドを使用することでした。ここに例があります。

...
 // 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);
...
于 2014-02-28T18:37:26.683 に答える