title: Why I don't see record in database from my test project?
body: <p>Hї!</p>
  
  <p>I have wrote test for my application. I need add item to database throught UI interface (using robotium) and then I want to check if item exists in database using SQLiteDatabase.</p>
  
  <p>Item is added succesfully (I see new record in database after test finished), but isExistsInDb in my test class returns false. I do not understand why. Could you please help me.
  Thanks!</p>
  
  <p>Activity class:</p>
  
  <pre><code>public abstract class EditActivity {
  
  
     // Some code .....
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          initButtonCancelOk();
      }
  
      protected void validateAndSave() {
          try {
              formValidator.validateAll();
              if (formValidator.isFormValid()) {
                  DatabaseOpenHelper doh = new DatabaseOpenHelper(this);
                  Dao d = new Dao(doh);
                  d.add(fetchObjectFromUi());
                  finish(); // destroy this activity
              } else {
                  ToastImage.makeImageText(context,
                          R.drawable.warning,
                          formValidator.getMessages(),
                          Toast.LENGTH_SHORT
                      ).show();
              }
          } catch (Exception e) {
              Toast.makeText(context, " Error during validate form ", Toast.LENGTH_LONG).show();
              e.printStackTrace();
          }
      }
  
      private void initButtonCancelOk() {
          btnOk = (Button) findViewById(R.id.btn_ok);
          btnOk.setOnClickListener(new View.OnClickListener() {
  
              @Override
              public void onClick(View v) {
                  validateAndSave();
              }
          });
      }    
  }
  </code></pre>
  
  <p>Test class:</p>
  
  <pre><code>public class AddItemSmokeTest extends extends ActivityInstrumentationTestCase2&lt;EditActivity&gt; {
  
      protected Activity activity;
      protected Solo solo;
  
      public AddItemSmokeTest() {
          super("com.myapp", EditActivity.class);
          Intent i = createIntent(2);
          setActivityIntent(i);
          activity = getActivity();
          solo = new Solo(getInstrumentation(), activity);
          solo.sleep(1000); // interval between tests
      }
  
      protected Intent createIntent(long transType) {
          Intent i = new Intent();
          i.putExtra(INTENT_VALUE_MODE_NAME, MODE_INSERT_TRANSACTION);
          i.putExtra(INTENT_VALUE_TYPE_ID_NAME, transType);
          return i;
      }
  
      @Override
      protected void tearDown() throws Exception {
  
      }
  
      protected void setIncomExpenseData(AbsTransIncomeExpenseTestData testData) {
          solo.pressSpinnerItem(CATEGORY_SPN_INDEX, testData.getCategorySpinnerPos());
          solo.pressSpinnerItem(ACCOUNT_SPN_INDEX, testData.getAccountSpinnerPos());
          solo.typeText((EditText) activity.findViewById(com.rirdev.moneycounter.R.id.et_sum), testData.getSum());
          solo.typeText((EditText) activity.findViewById(com.rirdev.moneycounter.R.id.et_comment), testData.getComment());
      }
  
      @Smoke
      public void testAddIncomeTransaction() throws Exception {
          initForType(TransactionType.INCOME);
          AbsTransIncomeExpenseTestData testData = new IncomeTestData();
          setIncomExpenseData(testData);
          solo.clickOnButton(OK);
          //solo.getActivityMonitor();
          assertTrue( 
                      "Item" + testData.getComment() + " was not added ",
                      isExistsInDb(activity, Transactions.TABLE_NAME, Transactions.DESCRIPTION, testData.getComment())
                    );
      }
  
      protected static boolean isExistsInDb(Context context, String tableName, String commentFieldName, String comment) {
  
          DatabaseOpenHelper doh = new DatabaseOpenHelper(context);
          SQLiteDatabase db = doh.getDatabaseReadable();
          Cursor cursor = null;
          try {
              String query = "SELECT COUNT(*) FROM " + tableName + " WHERE " + commentFieldName + " = \"" + comment + "\"";
              cursor = db.rawQuery(query, null);
              cursor.moveToFirst();
              if (cursor.getInt(0) &gt; 1) {
                  return true;
              }
              return false;
          } finally {
              if (cursor != null) {
                  cursor.close();
              }
              db.close();
              doh.close();
          }
  
      }
  
  }
  </code></pre>
  
  <p><strong>Update:</strong></p>
  
  <p>If I run test the second time it is passed because in database exists item added by previous test.</p>