How to mock Build.VERSION.SDK_INT using mockk

后端 未结 1 440
刺人心
刺人心 2021-01-17 17:21

How can I mock Build.VERSION.SDK_INT in mockk?

I\'ve done the following:

@Test
fun testFoo(){
    mockkStatic(Build::class)
    mockkStatic(Build.VER         


        
1条回答
  •  被撕碎了的回忆
    2021-01-17 17:54

    You can build a wrapper around the Build config like this

    object MyAppBuildConfig {
        fun getVersionSDKInt(): Int {
            return Build.VERSION.SDK_INT
        }
    }
    

    Then mock the MyAppBuildConfig with mockkObject and return your desire version number

        mockkObject(MyAppBuildConfig)
        every { MyAppBuildConfig.getVersionSDKInt() } returns 22
    

    0 讨论(0)
提交回复
热议问题