我怎么能测试一个方法是不是被称为非模拟对象?

我有一个测试如下,在给定的情况下,我想确保mainPresenter.presenterFunction()不被调用。

 class MainPresenterTest { val mainPresenter: MainPresenter val mainView: MainView val mainBridge: MainBridge init { mainView = mock(MainView::class.java) webBridge = mock(MainBridge::class.java) mainPresenter = MainPresenter(mainView, mainBridge) } @Before fun setUp() { MockitoAnnotations.initMocks(this) } @Test fun simpleTeset1() { // Given whenMock(mainView.viewFunctionCondition()).thenReturn(true) // When mainPresenter.onTriggger() // Then verify(mainView).viewFunction1() verify(mainPresenter, never()).presenterFunction() verify(mainView, never()).viewFunction2() } } 

然而它错误地指出

 org.mockito.exceptions.misusing.NotAMockException: Argument passed to verify() is of type MainPresenter and is not a mock! Make sure you place the parenthesis correctly! 

错误是在线verify(mainPresenter, never()).presenterFunction()

预计主要mainPresenter者不是模拟对象。 我怎么能测试一个被称为非模拟对象的方法?

我看到如何验证一个非模拟对象的方法调用的答案? ,但仍然使用模拟和间谍。 我希望找到一种方法,而不需要嘲笑我已经拥有的类实例。

(注:以上是用Kotlin写的)

根据定义,这是行不通的。

模拟框架只能verify模拟对象的调用。 他们无法知道他们无法控制的物体是否发生了什么。 你要么嘲笑你的主持人,取而代之的是存根或…

好吧,我认为这是唯一的两个选择。