MVP Mockito 單元測試

引用內容:
//測試庫
// Dependencies for local unit tests
testImplementation deps.junit
testCompile deps.mockito.core
testImplementation deps.hamcrest
// Android Testing Support Library’s runner and rules
androidTestImplementation deps.atsl.runner
androidTestImplementation deps.atsl.rules

// Dependencies for Android unit tests
androidTestImplementation deps.junit
androidTestCompile deps.mockito.android
androidTestCompile deps.mockito.core

// Espresso UI Testing
androidTestImplementation deps.espresso.core
androidTestImplementation deps.espresso.contrib
androidTestImplementation deps.espresso.intents
androidTestImplementation deps.espresso.idling
implementation deps.espresso.idling_resource

// Resolve conflicts between main and test APK:
androidTestImplementation deps.support.annotations
androidTestImplementation deps.support.v4
androidTestImplementation deps.support.recyclerview
androidTestImplementation deps.support.app_compat
androidTestImplementation deps.support.design

下面是測試代碼

    @Mock
    private lateinit var mView: MaterialManagermentClassifyContract.View

   @Before
    fun setUp() {
        MockitoAnnotations.initMocks(this)

   // The presenter wont't update the view unless it's active.
       `when`(mView.isActive()).thenReturn(true)
    }

注意Contract.View中不可以有fragment的引用,要不會報錯,這個問題折騰了一天

結構
Mocking final types, enums and final methods
添加/mockito-extensions/org.mockito.plugins.MockMaker
並且內容爲mock-maker-inline
方式 final 方法報錯

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章