How to access file resources in JUnit tests

By | January 30, 2015

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());

2 thoughts on “How to access file resources in JUnit tests

Leave a Reply

Your email address will not be published. Required fields are marked *