引用内容:
//测试库
// 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 方法报错