Page tree
Skip to end of metadata
Go to start of metadata

Kotlin中使用Mockito

1. 类要Open

2. 方法要Open

3. when要写成`when`

4. return Unit的,要写成doReturn/doAnswer().when(mock/spy).method()形式,即先return/answer再when,注意when的参数是mock/spy对象而不是方法的返回值

5. Mock suspend function, 参考 https://stackoverflow.com/questions/53098975/mocked-suspend-function-returns-null-in-mockito

 

示例代码
  • No labels