Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use class from test scope in other module [duplicate]

I have a module as part of a framework that provides common features to other modules. I have created a class (UtilitiesForTesting) that provides some utils to be used only in my tests, so it's stored in test section of the module.

The module has the following structure:

project
    -src
       -main
         -java
           -com
             -company
               -product
                 +Foo
       -test
         -java
           -com
             -company
               -product
                 +FooTest
               -utility
                 +UtilitiesForTesting

UtilitiesForTesting class is visible inside the project but when I compile it the resulting jar does not contains any test class.

Now I want to use the modules in other modules, because I need this common functionality, but also I want to use testing utilities.

I don't want to place UtilitiesForTesting in the /main section, since I don't want to allow the use of this class in production code, only in test.

I want to have just a module that provides production classes to other module and test util to the same module, but restricting using the test utilities in the /main section.

Is there any way to use a class of the test scope of a module in other module?

like image 905
Ezequiel Avatar asked Sep 01 '25 16:09

Ezequiel


1 Answers

In your pom.xml, under maven-jar-plugin, add below goal.

`<goal>test-jar</goal&gt`

All the files under src/test/java are compiled and bundled into artifact-test.jar.

In another module, if u want to use this artifact-test jar, use below configuration in dependency tag.

 `<artifactId>artifactid</artifactId>
<type>test-jar</type>'
like image 139
kswaughs Avatar answered Sep 04 '25 07:09

kswaughs