首页 > 解决方案 > Mockito 如何验证分配?

问题描述

是的,我知道我不应该测试状态而是行为,但是 Android AdMob 实施要求我将 a 分配FullScreenContentCallback给返回的InterstitialAd并且我想测试它是否发生:

 override fun onAdLoaded(ad: InterstitialAd) {
                ad.fullScreenContentCallback = FullscreenPluginCallback(InterstitialAdPluginPluginEvent, notifyListenersFunction)
            }

我需要测试ad.fullScreenContentCallback分配的。我努力了

   listener.onAdLoaded(interstitialAdMock)

    assertNotNull(interstitialAdMock.fullScreenContentCallback)

                AdInterstitialExecutor.interstitialAd = null
                var contentCallback: FullScreenContentCallback? = null

                Mockito.`when`(interstitialAdMock.fullScreenContentCallback).thenReturn(contentCallback)
                val listener = InterstitialAdCallbackAndListeners.getInterstitialAdLoadCallback(pluginCall, notifierMock)
                // ACt
                listener.onAdLoaded(interstitialAdMock)

                assertNotNull(contentCallback)

标签: kotlinmockito

解决方案


推荐阅读