1

I am trying to make a mojo that takes all the unit tests from all the modules that have a certain annotation made by me. The problem is that I can't access the unit tests from any module.
The module structure looks like this:

|--ModuleA (depends on Module D)
|--ModuleB (depends on Module D)
|--ModuleC (depends on Module D)
|--ModuleD (the mojo)

The question is how to access or retrieve the unit test classes of each module when the mojo runs for it.

6
  • your test should be under /src/test/java. This module organisation is packaged already in jar ? Commented May 5, 2016 at 21:17
  • Yes, the test are under /src/test/java. And each module has its own tests and pom.xml. I am using the following example to retrieve the classes, but as I said, I can't access the classes from unit tests stackoverflow.com/questions/13128552/… Commented May 5, 2016 at 21:24
  • So you are trying to write a Maven plugin? Yes and what are those other modules for? Commented May 5, 2016 at 22:38
  • I am trying to write a Maven plugin for the project I am working on. The other modules are the main modules of the project that beside the usual classes it contains the unit tests for the classes, and that are the unit tests classes that I am trying to get Commented May 6, 2016 at 9:56
  • Why the mojo must retrieve unit test classes? Unit tests verifies regular java code. When unit test pass, Roma locuta, cause finita, regular code is OK, unit test are not required anymore. Commented May 6, 2016 at 11:42

1 Answer 1

0

Updated Response since you told us about the dependencies of the modules. Best way to do this is : - moduleA, moduleB, moduleC built with maven
- generate test jars : add in your pom

 <plugin>
    <artifactId>maven-jar-plugin</artifactId>
    <version>2.4</version>
    <executions>
       <execution>
          <id>test-jar</id>
          <phase>package</phase>
          <goals>
             <goal>test-jar</goal>
          </goals>
       </execution>
    </executions>
 </plugin>
  • moduleD has dependcy on moduleA.jar,moduleB.jar,moduleC.jar & moduleA-test.jar,moduleB-test.jar,moduleC-test.jar

  • add in your moduleE's pom.xml for each module :

      <dependency>
         <groupId>com.rizze</groupId>
         <artifactId>moduleA</artifactId>
         <version>1.0.0</version>
      </dependency>
     <dependency>
         <groupId>com.rizze</groupId>
         <artifactId>moduleB</artifactId>
         <version>1.0.0</version>
      </dependency>
    
     <dependency>
         <groupId>com.rizze</groupId>
         <artifactId>moduleC</artifactId>
         <version>1.0.0</version>
      </dependency>
    
  • Module E is here to call all the test of Module A,B,C,D in the order you want to. Module E is making integration of all the modules in order to perform all the tests (as requested by you).

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

4 Comments

I can't add to moduleD those dependencies because it is creating a cyclic reference. The annotation is found in moduleD and the other modules have as dependency moduleD in order to add the annotation on the classes.
Than should add moduleE to global test
I am updating your questiion
Can you explain me what should I do with moduleE? I never used global test or found data that could help me

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.