Method setUp in android.test.AndroidTestCase not mocked

后端 未结 3 1903
伪装坚强ぢ
伪装坚强ぢ 2021-02-20 02:29

I\'m trying to come to terms with the new unit test feature of Android Studio. I\'ve followed the instructions on http://tools.android.com/tech-docs/unit-testing-support. The d

3条回答
  •  深忆病人
    2021-02-20 02:54

    From: https://sites.google.com/a/android.com/tools/tech-docs/unit-testing-support#TOC-Method-...-not-mocked.-

    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). This is to make sure your unit tests only test your code and do not depend on any particular behaviour of the Android platform (that you have not explicitly mocked e.g. using Mockito). If that proves problematic, you can add the snippet below to your build.gradle to change this behavior:

    android {
    
       // ...   
    
      testOptions { 
          unitTests.returnDefaultValues = true   
      } 
    }
    

提交回复
热议问题