Android unit test not mocked

后端 未结 3 1295
我寻月下人不归
我寻月下人不归 2020-12-05 12:46

I followed this guide https://sites.google.com/a/android.com/tools/tech-docs/unit-testing-support but i am stuck with this error:

junit.framework.AssertionF         


        
3条回答
  •  一向
    一向 (楼主)
    2020-12-05 13:31

    I think you trying to run tests with org.json.JSONObject which is part of Android Framework on pure jUnit.

    From docs:

    The android.jar file that is used to run unit tests does not contain any actual code - that is provided by the Android system image on real devices. Instead, all methods throw exceptions (by default).

    We are aware that the default behavior is problematic when using classes like Log or TextUtils and will evaluate possible solutions in future releases.

    You need to emulate Android environment you can use for this purpose Robolectric or InstrumentationTests

提交回复
热议问题