Android: Unit testing Android applications with Robolectric and Mockito

后端 未结 4 1527
没有蜡笔的小新
没有蜡笔的小新 2021-02-19 22:20

I have a Java library that uses a few things from the Android APIs. I\'d like to use Mockito to write unit tests for this library.

Is there a way I can go about this? <

4条回答
  •  再見小時候
    2021-02-19 23:07

    Take a look at android-mock. It's based on EasyMock 2.4 (so not quite as nice as Mockito but close).

    It gets around the limitations of the DalvikVM by pre-generating the mock classes at build time rather than runtime, and then bunding them with your compiled test code when deploying to the device.

    There's also a mocking framework called Borachio which I can't vouch for but looks promising (if you're happy to go through the motions of getting Scala to run on your device).

提交回复
热议问题