springBatch Bean 中有一个私有方法。配置类。
@Slf4j
public class EodDataDumpSpringBatchConfig {
private Resource getWriterResource(StepExecution stepExecution, Storage storage) {
String chunkUri = stepExecution.getJobParameters().getString(EodDataDumpConstants.CHUNK_URI);
String fileUri = chunkUri + stepExecution.getStepName();
Resource resource = new GoogleStorageResource(storage, fileUri);
return resource;
}
....
}
我正在写一个springBatchTest:
@SpringBatchTest
@EnableAutoConfiguration
@SpringJUnitConfig({EodDataDumpSpringBatchConfig.class})
@ExtendWith(MockitoExtension.class)
@TestPropertySource(locations = "classpath:application.properties")
@MockitoSettings(strictness = Strictness.LENIENT)
public class EodDataDumpSpringBatchTest {
@Value("file:src/test/resources/storageFile.csv")
private Resource resource;
@Test
public void dataDumpJobEndToEndTest() throws Exception {
}
}
我想模拟when().thenReturn语句中的私有方法。 我的意思是,当任何方法调用该私有方法时,它应该获得一个模拟的资源。
我尝试过:
你不能模拟私有函数,你可以将其更改为包私有,然后你就可以测试它了。
看看这个答案。