I'm trying to read a file from classpath like this in my unit test:
@Value("classpath:state.json")
Resource stateFile;
I have state.json
file in src/test/resources
directory.
When I try to read this file using stateFile.getInputStream()
, it doesn't return any contents. What am I doing wrong?
My test class is annotated like this
@RunWith(SpringRunner.class)
@SpringBootTest
I can see that the code fails if I try with a incorrect file. So I think its seeing the file in classpath but for some reason not reading contents.