我知道私有访问的方法可以使用1. reflection或2. powermockito进行测试,但是如何使用私有方法测试默认类并且父类是抽象的?
class AirSpaceBuilder extends SynchronizedSpace {
private Request request;
private Status status;
public AirSpaceBuilder (Log log, SpaceTable st, Collection locks, SpaceRequest request) {
super(log, st, locks, request.getAirSpace());
this.request = request;
}
private Status recursiveSignal() {
...
}
abstract class SynchronizedSpace {
private Collection sync;
private String requester;
private SpaceTable st;
private Log log;
...
}
我的第一个想法是从较高级别调用它,但随后它变成了集成测试并且失败了单元测试的目的。
编辑: 如果我错了,请纠正我,但这是你调用方法的方法吗?
Object airSpaceBuilder=Class.forName("com.airport.resource.AirSpaceBuilder").newInstance();
Method m = airSpaceBuilder.getClass().getDeclaredMethod("recursiveSignal");
m.setAccessible(true);
m.invoke(allocationFunction);