ClassPathResource classPathResource = mock(ClassPathResource.class);
whenNew(ClassPathResource.class).withArguments("studentInfo.json").thenReturn(classPathResource);
如果没有
PowerMockito
我应该如何编写 Spring 测试?
whenNew
和withArguments
结构用于PowerMockito
,我怎样才能只使用@SpringBootTest
而不使用PowerMockito
来实现它们?
之后我将读取mockito文件并检查该文件是否存在。
你可以这样使用它;
@SpringBootTest
public class Test {
@Autowired
private ResourceLoader resourceLoader;
@BeforeClass
void init() {
File file = resourceLoader.getResource("classpath:data/file.txt").getFile();
}
}