如何使用 Mockito 在模拟上显示所有调用

How to use Mockito to show all invocations on a mock(如何使用 Mockito 在模拟上显示所有调用)
本文介绍了如何使用 Mockito 在模拟上显示所有调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我有一个失败的单元测试,我不确定原因.我希望能够看到在被测系统中发生的模拟上的所有调用.这不是我想要的所有测试的行为,只是我需要快速调整以找出问题所在的测试.

I have a unit test that is failing and I'm unsure why. I want to be able to see all invocations on the mock that occur in the System Under Test. This is not the behavior that I want for all tests always, simply for a test that I need to quickly tweak to be able to figure out what's wrong.

但是,这似乎有点像 hack.是否可以在 Mockito 中本地执行此操作,而无需使用 Thread.currentThread().getStackTrace()?

However, it seems kind of like a hack. Is it possible to do this natively in Mockito, without having to use Thread.currentThread().getStackTrace()?

这不是首选,因为堆栈跟踪包括 Mockito 内部使用的所有其他调用.

This is not preferred, because the stack trace includes all the other invocations used internally by Mockito.

推荐答案

此功能自 Mockito 1.9.5 起内置.只需使用

This feature is builtin since Mockito 1.9.5. Just use

mock(ClassToMock.class, withSettings().verboseLogging())

这篇关于如何使用 Mockito 在模拟上显示所有调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Sending a keyboard event from java to any application (on-screen-keyboard)(将键盘事件从 java 发送到任何应用程序(屏幕键盘))
How to make JComboBox selected item not changed when scrolling through its popuplist using keyboard(使用键盘滚动其弹出列表时如何使 JComboBox 所选项目不更改)
Capturing keystrokes without focus(在没有焦点的情况下捕获击键)
How can I position a layout right above the android on-screen keyboard?(如何将布局放置在 android 屏幕键盘的正上方?)
How to check for key being held down on startup in Java(如何检查在Java中启动时按住的键)
Android - Get keyboard key press(Android - 获取键盘按键)