0

我正在尝试测试 android 内容提供程序。我正在编写与此处给出的代码类似的代码,插入数据库然后查询数据库,但有时且并非总是如此,返回的游标有 0 行。可能是什么问题?

public class MyProviderTestCase extends ProviderTestCase2<MyProvider> {

private MockContentResolver mMockResolver;
    ....
public MyProviderTestCase() {
    super(MyProvider.class, "com.example.MyProvider");
}

protected void setUp() throws Exception {
    super.setUp();
    mMockResolver = getMockContentResolver();
}

protected void tearDown() throws Exception {
    super.tearDown();
}

@SmallTest
public void testInsertAndUpdate() {
    ...
    SomeObject someObject = ...;
    Uri insertedUri = mMockResolver.insert(MyrProvider.URI, someObject.createContentValues());

    assertNotNull(insertedUri);
    Log.d("test insert and update and delete:inserteduri", insertedUri+"");

    Cursor c = mMockResolver.query(MyProvider.URI, null, null, null, null);
    assertNotNull(c);

    assertTrue(c.moveToFirst());// This assertion fails sometimes
}

}

4

0 回答 0