【发布时间】:2019-09-15 00:00:16
【问题描述】:
我正在为从抽象类扩展的类编写单元测试,子类的一个函数将调用 super void 函数和函数。
//two classes in different package
public abstract class AbstractBo {
private Map myMap = new HashMap();
protected void load(String jsonString) {
//convert the jsonString parameter to map, and set to myMap
}
public String getItem(String key) {
return myMap(Key);
}
}
public class SubBo extends AbstractBo {
public String submit(String initString) {
//init a map by super function
this.load(initString);
return this.getItem("myName");
}
}
我只是想测试提交功能,模拟加载和 getItem 功能。我是 powermock 的新手。
【问题讨论】:
-
您应该认真考虑更改您的代码,而不是指望 PowerMock 来解决您难以测试的设计。例如,请参阅stackoverflow.com/questions/3467801/…。
标签: java unit-testing powermock