Tag: superclass

我可以用Mockito / Powermock模拟一个超类的构造函数吗?

是否可以使用Mockito和可选的Powermock来模拟超类S ,以便对超类S任何调用(包括对S()构造函数的调用)都被模拟? 所以使用下面的例子,如果我使用MockS用MockS替换S , MockS对super()的调用是否会使用MockS中的构造MockS ? class S { S() { // Format user’s hard drive, call 911, and initiate self-destruct } } class T extends S { T() { super(); } } class Test { @Mock private S mockS; new T(); // T’s call to super() should call the mock, not the destructive S. […]