Android Unit Tests Requiring Context

后端 未结 8 1777
抹茶落季
抹茶落季 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:08

    You can derive from MockContext and return for example a MockResources on getResources(), a valid ContentResolver on getContentResolver(), etc. That allows, with some pain, some unit tests.

    The alternative is to run for example Robolectric which simulates a whole Android OS. Those would be for system tests: It's a lot slower to run.

提交回复
热议问题