Junit Powermockito无法模拟超级调用
因此,基本上我正在尝试使用powermockito为使用Web服务的服务类的适配器编写Junit 我有一个带有构造函数的适配器,inturn通过调用一个超类在它自己的构造函数中创建一个新的服务对象。我必须测试我的适配器。我已经使用powermockito来模拟我的适配器以及我的服务类,但是我认为被模拟的对象不能执行超级调用。下面是我的代码结构。我希望超类在调用时返回我的模拟对象Junit Powermockito无法模拟超级调用,junit,mockito,Junit,Mockito,因此,基本上我正在尝试使用powermockito为使用Web服务的服务类的适配器编写Junit 我有一个带有构造函数的适配器,inturn通过调用一个超类在它自己的构造函数中创建一个新的服务对象。我必须测试我的适配器。我已经使用powermockito来模拟我的适配器以及我的服务类,但是我认为被模拟的对象不能执行超级调用。下面是我的代码结构。我希望超类在调用时返回我的模拟对象 public class CommonPoolingServiceAdp { private CPSSecu
public class CommonPoolingServiceAdp {
private CPSSecurity cpsServicePort;
public CommonPoolingServiceAdp() {
CommonPoolingService service= new CommonPoolingService();
cpsServicePort=service.getCommonPoolingServicePort();
}
public SercurityDataResponse getBroadcastElements(broadcastReqObj)
{
SercurityDataResponse=null;
response=cpsServicePort.getBroadcastElements(broadcaseRequestObj);
}
}
public class CommonPoolingService extends Service {
{
static
{
//few mandatory initializations
}
public CommonPoolingService()
{
super(WSDL_Location,QName);
}
public CSPSecurity getCommonPoolingServicePort() {
return super.getPort(QName);
}
}
}
请分享更多的代码。顺便说一下,这就是模拟超类方法的方式:
public class SuperClass {
public void method() {
methodA(); // I don't want to run this!
}
}
public class MyClass extends SuperClass{
public void method(){
super.method()
methodB(); // I only want to test this!
}
}
@Test
public void testMethod() {
MyClass spy = Mockito.spy(new MyClass());
// Prevent/stub logic in super.method()
Mockito.doNothing().when((SuperClass)spy).methodA();
// When
spy.method();
// Then
verify(spy).methodB();
}
希望,这会有所帮助。您可以发布当前的测试代码吗。那么您希望调用
super.getPort(QName)
返回一个模拟的CSPSecurity
?