Need help to write a unit test using Mockito and JUnit4

前端 未结 10 1078
余生分开走
余生分开走 2020-12-15 04:06

Need help to write a unit test for the below code using Mockito and JUnit4,

public class MyFragmentPresenterImpl { 
      public Boolean isValid(String value         


        
10条回答
  •  青春惊慌失措
    2020-12-15 04:29

    This is a known issue, due to a clause in Testing Fundamental of Android which says:

    You can use the JUnit TestCase class to do unit testing on a class that does not call Android APIs.

    The default behavior is problematic when using classes like Log or TextUtils.

    To sum up:

    1. android.jar is mock before, so some Android API return value may not be as expected.
    2. JUnit itself is a single measure for the java code, so try not to use the Android API methods.

    Source: http://www.liangfeizc.com/2016/01/28/unit-test-on-android/

提交回复
热议问题