2

I want to add test resources from another module.

My tests ran ok with the following

<testResources>
    <testResource>
        <directory>DEPENDENCY_A/src/main/resources</directory>
    </testResource>

</testResources>

DEPENDENCY_A has pom packaging, however, my tests cannot the same external resources by adding it as a test-pom-dependency.

<dependency>
    <groupId>DEPENDENCY_A</groupId>
    <artifactId>DEPENDENCY_A</artifactId>
    <type>pom</type>
    <scope>test</scope>
</dependency>

Please help :) How do I access resources in DEPENDENCY_A in my unit tests? Maybe I'm missing something obvious in Java basics :(

lingo_journey
  • 653
  • 1
  • 8
  • 22
  • 1
    Looks like duplicate. See this http://stackoverflow.com/questions/2247199/share-test-resources-between-maven-projects – codesalsa Jul 21 '15 at 23:48

1 Answers1

0

Dependencies are artifact, libraries, jars, ... not resources. So this idea is not suitable.

You can use the copy-resources goal of the Maven Resources Plugin:

copies resources to an output directory. This goal requires that you configure the resources to be copied, and specify the outputDirectory.

See also Maven model, resource.

Gerold Broser
  • 14,080
  • 5
  • 48
  • 107
  • How do I access resources/file in DEPENDENCY_A_JAR in my unit tests? Maybe I'm missing something obvious in Java basics :( – lingo_journey Jul 22 '15 at 09:35
  • @lingo_journey If you use [Maven's Standard Directory Layout](https://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html) test resources reside in `src/test/resources` of your Maven project. – Gerold Broser Jul 22 '15 at 10:14
  • Thanks, if I want a Unit test to use resources from an external jar... what's the best practice please? How do I run the copy-resources goal against a jar? – lingo_journey Jul 22 '15 at 12:12
  • @lingo_journey Did you follow the link codesalsa gave you in the comment to your question? – Gerold Broser Jul 22 '15 at 12:18
  • Thanks, I did, however, I need to use the "main" (instead of test) resources of external JAR-A. – lingo_journey Jul 22 '15 at 12:36