In maven, any file under src/test/resources
is copied to target/test-classes
. How to access these resource files in JUnit? Using the class’s resource. It will locate the file in the test’s classpath /target/test-classes
.
URL url = this.getClass().getResource("/" + TEST_FILENAME); File file = new File(url.getFile());
Your approach for reading local file with Junit doesn’t work. I get a NullPointerException.
Can you find the test file under “target/test-classes”? Did you use “mvn test”?