如何使用PowerMock和Mockito模拟默认构造函数? [英] How to mock the default constructor using PowerMock with Mockito?
本文介绍了如何使用PowerMock和Mockito模拟默认构造函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我应该如何使用PowerMock-Mockito(No EasyMock)模拟默认构造函数?
How should I mock the default constructor using PowerMock-Mockito(No EasyMock) ?
我要这样做,以访问对象的值.
I want to access the values of the object by doing this.
例如:
Class A {
public A()
{
}
}
推荐答案
PowerMockito.whenNew
API应该用于执行此操作.有关更多信息,请参见此链接:如何模拟新对象的构建
PowerMockito.whenNew
API should be used to perform this. See this link for further information: How to mock construction of new objects
这篇关于如何使用PowerMock和Mockito模拟默认构造函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文