Load test resources in another module?

I am using an abstract class in another module to read and write input for my test data with:

package src/main/java/path/to/my/base/testclass; InputStream stream = getClass().getResourceAsStream(filename); 

filename , for example, "test.txt" located in src/main/resources/path/to/my/base/testclass

As long as I put this abstract class in the same module as my test classes, everything works fine. Then I extract the acstract class (as well as resources) into another module, compile, add to pom, etc. Result: my test implementation is working fine, but: I get an IO exception as file could not be found.

What am I missing here? Why does an abstract class work in one module, but not inside?

+4
source share
1 answer

Testing resources are intended only for these artifact tests; they are not deployed.

There are two possible ways:

  • Dirty: make your application, deploy a test bank with the main bank , and add this as a dependency with the TEST area to the second artifact.
  • Clear: create a separate test artifact for the base test classes and shared test resources. Important: in this artifact, nothing happens in src / test, and everything goes in src / main. Link to this test artifact from both artifacts with the TEST extension.
+2
source

All Articles