1

From the maven docs , we get that if direct dependency of our project A have scope test and its transitive dependency have scope test , then that transitive dependency won't be taken in test classpath of our project A

[Project A] -> [Direct Dependency of A , say  X (scope test)] -> [Direct dependency of X , say Y (scope test)]

This makes me think of a scenario (possible or not , you decide)

If execution of some test in our project A depends on code of some test in project X , then maven will never be able to run the test of A as it will never take Y in test classpath.

In such scenario what should we do ? If you say such scenario cannot exist , why ?

Number945
  • 4,631
  • 8
  • 45
  • 83

1 Answers1

2

Usually tests are not included into a project's jar-file (otherwise these are not tests but a part of the project).

If you want to reuse the test code in another project, you should create a separate jar file containing test classes and put it on the list of your dependencies with the scope of 'test'. In other words, if your project A depends on project X, you should explicitly specify that, does not matter if it's the test code or not.

For more information on it check this: How to create a jar containing test classes

Pavel Smirnov
  • 4,611
  • 3
  • 18
  • 28