I have the following project structure (both project
and module
contain pom.xml
files):
Now, in the test class SomeTest.java
I want to test some functionality using image.jpg
in the resources folder.
I'm using the following file path as a constant:
private static final String IMG_PATH = "src/test/resources/image.jpg";
I then read in this as a file using
BufferedImage image = ImageIO.read(new File(IMG_PATH));
When running this project with the following Maven configuration, everything works fine.
However, when running the unit test manually, the image cannot be found, because the file path is different.
Printing the file path shows the following as an absolute path:
C:\Users\Name\Documents\project\src\test\resources\image.jpg
As you can see, it's project/src
and not project/module/src
.
How can I configure JUnit so that it's root folder for resources is the Maven module folder and not the project folder?
I want to be able to run the tests using Maven as well as by hand for debugging.