How to mock Context using Mockito?

前端 未结 3 1089
迷失自我
迷失自我 2021-02-11 19:44

I\'m using Context to access system level services like WifiManager and BluetoothManager. How to mock this getApplicationContext() using Mockito?

相关标签:
3条回答
  • 2021-02-11 20:05

    If you want to get the context with Kotlin and Mockito, you can do it in the following way:

    mock(Context::class.java)
    
    0 讨论(0)
  • 2021-02-11 20:20

    Let's have a look at the following class: MockContext

    If you need more insight, check the Official Testing Fundamentals page

    0 讨论(0)
  • 2021-02-11 20:20
        Context context = mock(Context.class);
    
    0 讨论(0)
提交回复
热议问题