Java – how mockito creates instances of mock objects

When I create a mock object of class employee It does not call the constructor of the employee object I know that internal mockito uses cglib and reflection to create a proxy class and extend the class to mock If it does not call the constructor of employee, how is the mock instance of Employee class created?

Solution

Mockito uses cglib to generate class objects However, to instantiate such an object, it uses objenesis http://objenesis.org/tutorial.html

Objenesis can instantiate an object without a constructor using various techniques (i.e. calling objectstream. ReadObject, etc.)

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>