Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create test resources folder manually for unit test

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.

like image 282
Mahmoud Saleh Avatar asked Nov 21 '11 08:11

Mahmoud Saleh


People also ask

Where do you put test resources?

a resource is a file in the class path folder structure for your project. this is important because your test resources will be put in your test-classes folder hierarchy and your main resources will be put in your classes folder hierarchy — both in your target folder.


1 Answers

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.

like image 77
Jan Zyka Avatar answered Sep 18 '22 23:09

Jan Zyka