1
votes

I have a JUnit test located within my project package in the location:

Java Resources > unittests > ActionTest.java

I am trying to use an InputStream in one of my tests that would take in a static file located in another part of my project package:

WebRoot > TestFiles > sampleFile.txt

Is there a way to go about passing the classpath of the file to the InputStream somehow? Or will I need to move the sampleFile.txt somewhere else within my project?

I have tried defining the InputStream like so:

InputStream fileStream = getClass().getResourceAsStream("sampleValidPatientList.txt");
1

1 Answers

1
votes

This will work if WebRoot/TestFiles is in the classpath.

I generally create a /test-resources folder and put test data into it. If I add it to the test CLASSPATH my tests can always find them.