mockito如何创建mock对象的实例

How does mockito create an instance of the mock object(mockito如何创建mock对象的实例)
本文介绍了mockito如何创建mock对象的实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

限时送ChatGPT账号..

当我创建一个说类 Employee 的模拟对象时.它不调用 Employee 对象的构造函数.我知道内部 Mockito 使用 CGLIb 和反射,创建一个代理类,将类扩展为模拟.如果不调用employee的构造函数,employee类的mock实例是如何创建的?

When i create a mock object of say class Employee. It doesnt call the constructor of Employee object. I know internally Mockito uses CGLIb and reflection, creates a proxy class that extends the class to mock. If it doesnt call the constructor of employee how is the mock instance of employee class created ?

推荐答案

Mockito 使用 CGLib 生成类对象.然而,要实例化这个类对象,它使用 Objenesis http://objenesis.org/tutorial.html

Mockito uses CGLib to generate class object. However to instantiate this class object it uses Objenesis http://objenesis.org/tutorial.html

Objenesis 能够使用各种技术(即调用 ObjectStream.readObject 和类似方法)在没有构造函数的情况下实例化对象.

Objenesis is able to instantiate object without constructor using various techniques (i.e. calling ObjectStream.readObject and similar).

这篇关于mockito如何创建mock对象的实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

相关文档推荐

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 - 获取键盘按键)