0

I'm trying to test my SimpleFrgament class using Roboelectric. Now the scenario is - the fragment opens sqlite DB and fetches Page(Pojo class) from it and based on the values inside the POJO my layout is inflated.

Here is the code:

MyDb dbInstance = new MyDb(getActivity());
dbInstance.open();
Page currentPage = dbInstance.retrievePage(pageId, selectedLang);
dbInstance.close();
if (currentPage.getStatus() == null || currentPage.getStatus().size() == 0) {
    llStatus.setVisibility(View.GONE);
} else {
    String color = currentPage.getStatus().get(0).getColor();
    if (color.equals("red"))
        tvStatus.setTextColor(Color.RED);
    else
        tvStatus.setTextColor(Color.GREEN);
    tvStatus.setText(currentPage.getStatus().get(0).getTitle());
}

Now this currentPage is obviously null and even if I fill it with some dummy values in my test code, the above piece of code will override it with null. So what is the approach to bypass the code or shadow the local database values?

Eugen Martynov
  • 19,888
  • 10
  • 61
  • 114
indi mars
  • 133
  • 3
  • 8
  • 1
    You can bundle tests with some pre-filled database or you can run about insertion of the page into db before. But the better way to pass DB instance instead of creating it and mock it in the test – Eugen Martynov Aug 09 '15 at 19:37
  • @EugenMartynov can you help me here-- http://stackoverflow.com/questions/32499667/simpletestcursor-robolectric-3-0-compilation-issue – indi mars Sep 10 '15 at 10:44

0 Answers0