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.

jeorfevre
  • 2,286
  • 1
  • 17
  • 27
Catalin
  • 69
  • 1
  • 1
  • 10
  • your test should be under /src/test/java. This module organisation is packaged already in jar ? – jeorfevre May 05 '16 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 http://stackoverflow.com/questions/13128552/how-to-scan-classes-for-annotations – Catalin May 05 '16 at 21:24
  • So you are trying to write a Maven plugin? Yes and what are those other modules for? – khmarbaise May 05 '16 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 – Catalin May 06 '16 at 09: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. – michaldo May 06 '16 at 11:42
  • The mojo has to make an html with each test class and its methods from the entire project – Catalin May 06 '16 at 11:48

1 Answers1

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).

jeorfevre
  • 2,286
  • 1
  • 17
  • 27