Search code examples
springunit-testingmavenjunit

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.


Solution

  • 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.