title: Android Provider Testing
body: <p>I am trying to test android content providers. I am writing code similar to given here, inserting into a db and then querying the db, 
  but sometimes and not always, the returned cursor has 0 rows. What may be the problem? </p>
  
  <pre><code>public class MyProviderTestCase extends ProviderTestCase2&lt;MyProvider&gt; {
  
  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
  }
  </code></pre>
  
  <p>}</p>