【发布时间】:2022-06-11 15:02:47
【问题描述】:
我有以下方法,我需要用 Spock 编写单元测试。
private Credentials getCredentials() throws IOException {
return GoogleCredentials.fromStream(new FileInputStream(gcpKey));
}
我无法模拟“new FileInputStream(gcpKey)”部分。
到目前为止我尝试过的内容如下。 1.
given: "mock service"
InputStream inputStream = Mock(InputStream.class)
FileInputStream fileInputStream = Stub(FileInputStream.class){
new FileInputStream(_) >> inputStream
}
给定:“模拟服务”
FileInputStream fileInputStream = GroovySpy(name : "name")
1 * new FileInputStream("name")
任何人都对此有想法
【问题讨论】:
标签: java spring-boot unit-testing spock