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 :(

1

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

5 Comments

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 If you use Maven's Standard Directory Layout test resources reside in src/test/resources of your Maven project.
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 Did you follow the link codesalsa gave you in the comment to your question?
Thanks, I did, however, I need to use the "main" (instead of test) resources of external JAR-A.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.