Reputation: 1799
A project I am working on uses JUnit for unit tests, with Jenkins to run them. Building is via Ant.
A particular test I have requires a csv file of test data - so my question is how to access this from within my test.
Currently I try to read the test data from the following path:
"/resources/com/(company)/(project)/(feature)/test_data.csv"
For test file:
"test/com/(company)/(project)/(feature)/test_file.java"
I then get the file handle like this:
final File file = new File(this.getClass().getResource(path).getFile());
The file tree is:
src
com/(path)/source files
test
com/(path)/test files
resources
com/(path)/resource files
This runs fine on my local machine (built using Eclipse), but not within Jenkins (built using Ant), since the resources are not copied - any ideas what I'm doing wrong?
I have tried to add the following to build.xml:
<target name="init">
<mkdir dir="${bin.dir}" />
<copy includeemptydirs="false" todir="${bin.dir}">
<fileset dir="test/resources" />
</copy>
</target>
However, it is copying into the class directory (bin/com/(path)/
), rather than the resources directory (bin/resources/com/(path)/
). Since Eclipse uses the latter, it would be best to have them match so that the tests can be run using either method.
As an aside, is there somewhere else that it should be stored?
Upvotes: 0
Views: 464
Reputation: 1799
Ok, I think I solved it with:
<mkdir dir="${bin.dir}/resources" />
<copy includeemptydirs="false" todir="${bin.dir}/resources">
<fileset dir="test/resources" />
</copy>
If you have any feedback on whether this is the right way to do all of this, then I would love to hear it!
Upvotes: 1