Demo Joomla! 1.5

Visit the Joomla! 1.5 demo site to see my extensions live running

Demo Joomla! 2.5

Visit the Joomla! 2.5 demo site to see my extensions live running

Support

Do not submit a bug report if you need technical support or have questions.

Forums

Post your suggestions ask for help in the community forums

Wiki

Visit the Wiki extensive and up to date documentation at your fingertips.

Contact Me

Missing images/links, any comments, suggestions, need help? Contact me

Skype

Need desperately help?
Skype Me™! But dont abuse of it!

maven2 Unit Test code reuse and dependencies

User Rating:  / 0
PoorBest 

apache_maven

In a multi modules project where you have write API or common code for unit tests in one project and want to reuse these in the tests for another project. Maven will crash during the compile phase if you do not make the following.

Maven rules of the game:

  • The main code in src/main/java is visible across modules if you did specify project
    dependencies in pom.xml.
  • Test code reside in src/test/java and is not shared across modules, moreover
  • Test code can use any code from src/main/java but not the other way around, which
    make sense as we want to clearly separate test code (junit testcases) from code shipped.

The solution is to create additional test jar for each module, this is done by putting in the
parent pom (lets call it parent-pom.xml)

inside the <build></build> tags the following:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <executions>
      <execution>
        <goals>
          <goal>test-jar</goal>
        </goals>
      </execution>
    </executions>
</plugin>

This will create for each modules an additional jar named {artifactId}-{version}-tests.jar
during the goal test-jar

Now for every modules where you want to reuse test classes, all you have to do in to put in every
modules pom.xml a dependency to that test jar by adding the tests classifier

 <dependency>
     <groupId>yourGroup</groupId>
     <artifactId>yourReusableModuleArtifact</artifactId>
     <version>0.1-SNAPSHOT</version>
     <classifier>tests</classifier>
     <scope>test</scope>
 </dependency>

 

This has work for me with Maven 2.0.8

You might also like:
Apache Maven 3 Cookbook
83 days ago
Apache Maven 3 Cookbook
  First a big thanks to Packt Publishing for having sent me this book to review! I did enj
Apache Maven 3 Cookbook Review
129 days ago
Apache Maven 3 Cookbook Review
Thanks to Packt Publishing for having sent me this book to review. I will publish a review in the
List conflicting dependencies in the Maven reactor
245 days ago
List conflicting dependencies in the Maven reactor
The Maven Dependency Plugin among other things include a dependency:analyze-duplicate The depe
Break Maven build when there is a dependency conflict
245 days ago
Break Maven build when there is a dependency conflict
Scenarios You want to control Maven during dependency resolution and break the build i
blog comments powered by Disqus
Parent Category: Framework
Category: Apache Maven

Donations

Thank You for supporting my work

Follow Me

Follow cedricwalter on Twitter Subscribe via RSS Subscribe via RSS Follow us on Facebook Follow us on Google+

Latest Articles

  • Thanks to Nathan Rennie-Waldock. you can have the latest PHP5 5.3.10 running in Ubuntu Oneiric, Natty, Maverick and Lu... ...
  • Download and install the latest  VMware Player 4.0.2 to run this Virtual Appliance “Ubuntu 11.10 x64 Server” ... ...
  • Download and install VMware Player 4.0.2 to run this Virtual Appliance “Ubuntu 11.10 x64 Server” Ready to user st... ...
  • Thanks to Ondřej Surý,  maintainer for some Debian packages, you can have the latest PHP5 maintained by Debian ... ...
  • Munin is a networked resource monitoring tool that can help analyze resource trends and "what just happened to ki... ...

Latest Comments

Popular Posts

rockettheme advertisement

dropbox logo

Help Us & Leave Feedback!

  • Do you have an excellent article idea you would like to read about here? Share it!
  • Do you have some interesting tips how we could improve our site?
  • Something missing here? Help us make this blog a better place, leave feedback!
We would love to hear from you! Be active! Write us now!

Blogs

Didier Beck Tech Head Brothers

google+ badge