我在单元测试下面的方法时遇到了一些问题。java - testing - 使用内部私有方法的lambda?
public List<GetSupplyChainResponse> getSupplyChains(){
List<GetSupplyChainsResponse> response = new ArrayList<>();
supplyChainRepository.findSupplyChainsWithCompound().forEach(result
-> response.add(getGetSupplyChainSimpleResponse(result)));
return response;
}
getGetSupplyChainSimpleResponse()
是同一类的getSupplyChains()的私有方法
是否有可能因此或者你有任何其他想法,我怎么能测试方法getSupplyChains()
定义的返回值?
您可以使用反射。看到这个http://stackoverflow.com/questions/11282265/how-to-call-a-private-method-from-outside-a-java-class –
你有什么问题?你有什么错误吗?也许你还想显示'getGetSupplyChainSimpleResponse()'方法,这样我们就可以看到那里发生了什么。 – px06
如果没有调用'private'方法的lambda表达式,则测试getSupplyChains()方法的方式与测试方法完全相同。 – Holger