Reputation: 33635
the sample application i am working on doesn't have a resources folder in test, i don't know why, so i am trying to create the resources folder in test manually as follows:
from eclipse: on the java resources > new source folder > src/test/resources
i can see now that the resource folder appears in test package, but question is, is there's any additional configuration should i do to maven or spring or unit test so i can work with resources folder and load files from it ?
please advise, thanks.
Upvotes: 6
Views: 15394
Reputation: 412
I post another answer for Gradle users
Edit .classpath file
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
...
<classpathentry kind="src" output="bin/test" path="src/test/java">
<attributes>
<attribute name="test" value="true"/>
<attribute name="gradle_scope" value="test"/>
<attribute name="gradle_used_by_scope" value="test"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="bin/test" path="src/test/resources">
<attributes>
<attribute name="test" value="true"/>
<attribute name="gradle_scope" value="test"/>
<attribute name="gradle_used_by_scope" value="test"/>
</attributes>
</classpathentry>
...
</classpath>
Upvotes: 1
Reputation: 17898
You either use maven standard directory layout (then maven includes it automatically) or you point maven to the resources in your pom file in build section as follows:
<testResources>
<testResource>
<directory>src/test/resources</directory>
</testResource>
</testResources>
Then you have the resources on classpath.
Upvotes: 11