Is it possible to do strict mocks with Mockito?

后端 未结 6 1399
傲寒
傲寒 2021-02-12 20:13

I\'d like to use strict mocks, at least when developing for the first time some tests against old code, so any methods invoked on my mock will throw an exception if I didn\'t sp

6条回答
  •  佛祖请我去吃肉
    2021-02-12 20:48

    In addition to the MockitoRule approach, if you don't need to use a specific test runner (and you are using Mockito 2.5.1 or higher), you could also consider using the MockitoJUnitRunner.StrictStubs runner, i.e.

    @RunWith(MockitoJUnitRunner.StrictStubs.class)
    

    (I would have commented on the post about MockitoRule, but don't have that ability yet)

提交回复
热议问题