Android Unit Tests Requiring Context

后端 未结 8 1785
抹茶落季
抹茶落季 2020-12-13 23:47

I am writing my first Android database backend and I\'m struggling to unit test the creation of my database.

Currently the problem I am encountering is obtaining a va

8条回答
  •  余生分开走
    2020-12-14 00:05

    Extending AndroidTestCase and calling AndroidTestCase:getContext() has worked fine for me to get Context for and use it with an SQLiteDatabase.

    The only niggle is that the database it creates and/or uses will be the same as the one used by the production application so you will probably want to use a different filename for both

    eg.

      public static final String    NOTES_DB      = "notestore.db";
      public  static final String   DEBUG_NOTES_DB = "DEBUG_notestore.db";
    

提交回复
热议问题