Whos Online

Joomla

We have 200 guests and 0 members online

    Forums

    We have 17 guests and 2 members online

    Tags

    android (7) anonymity (9) ant (10) apache (54) apple (7) atv (18) australia (8) bernardet (7) bombardier (7) book (7) browser (10) business (8) caliber30 (61) canon (9) cedricwalter (6) checklist (9) chrome (6) classpath (6) collection (7) continuousbuild (25) design (13) designpattern (23) desktop (7) development (28) DIY (9) draganflyer5 (9) dslr (14) eclipse (30) ek4 (8) electronic (18) enfrancais (66) FAQ (6) figures (13) firefox (20) firmware (7) flash (9) flickr (6) framework (12) fud (9) game (19) gaming (6) girls (6) google (68) gpl (8) gps (9) hacking (23) hdtv (7) hollidays (15) homecinema (14) homepage (20) howto (66) infrastructure (6) innoveo (7) iphone (6) italy (10) itsatrap (8) java (73) javascript (11) joke (11) joomla (215) joomla15 (33) joomlacloud (7) junit (9) kde (10) kyosho (62) links (17) linux (122) LittleBigPlanet (16) mambo (18) manual (8) manurhin (9) maps (6) maven (36) mediacenter (9) microsoft (52) modding (10) module (17) morespeed (16) motor (8) motorcycle (13) myhomepage (14) mysql (14) nas (14) neogeo (20) opencomment (27) opensource (61) opensuse (10) oss (7) p2p (7) patch (32) pc (12) pdf (8) php (26) picasa (7) plugin (65) privacy (9) projector (11) protection (7) ps3 (42) publicity (9) quad (18) raptor30 (7) rchelicopter (161) review (32) robot (9) robotic (7) rss (8) safety (8) scooter (29) security (62) securityimage (8) securityimage3 (6) securityimage4 (21) securityimage5 (19) securityimages (14) securityimages5 (6) server (17) simulator (8) smugmug (12) snk (16) software (31) sony (38) spammer (7) statistics (13) storage (7) subversion (6) suse (12) switzerland (7) teamcity (15) testing (9) thundertiger (20) tips (31) tomcat (7) tomtom (7) translatetofrench (8) trip (17) troubleshooting (7) tutorial (9) twitter (6) upgrade (15) vespa (10) video (17) vintage (8) watercooling (9) web2.0 (28) windows (14) xbmc (7) xbox (10) zurich (16) zürich (11)

    Skype me

    My status

    Follow me

    Facebook Digg LinkedIn MySpace Twitter Playstation network Xbox Live
    Digg Del.icio.us Reddit Simpy StumbleUpon Ask Facebook Slashdot Backflip Spurl MisterWong Netvouz Diigo Segnalo RawSugar Shadows Google Furl Newsvine Yahoo Technorati Live Blogmarks Netscape Fark Wink LinkaGoGo Bibsonomy FeedMe Magnolia Blue Tailrank Del.irio.us Y PlugIM SpotBack LinkSwarm

    Gallery

    Twitter

    Google Buzz


    Re: No related articles are displayed - Which missing plugins?
    22 hours ago,

    Re: No related articles are displayed - Try installing more updates of this and missing plugins, will do better and help to resolve this. Bravia | Timeline
    22 hours ago,

    did install recaptcha and akismet in my forum forums.waltercedric.com... so my buzz profile should not be polluted by spammers. Let see how it work in 2 days...
    4:17 PM Mar 10, 2010,

    Re: Fatal error in com_installer/controller.php in joomla 1.4 how to recover? - hello friend, I received a fatal error as Call to a member function setState() on a non-object in /home/ngi/public_html/administrator/components/com_installer/controller.php .please provide the solution. Thanks SP
    11:32 AM Mar 10, 2010,

    relations - in 21 and looking an aggrandizement to sex toys ? examine into into us at www.avi.vg... and upon the largest selction of vibrators, [url=www.avi.vg/category......
    11:54 PM Mar 09, 2010,
     
    Maven reusing test classes across multi modules projects Print E-mail
    User Rating: / 18
    PoorBest 
    Friday, 18 July 2008 22:14

    maven-logo-2
    Maven clearly differentiate "productive code"  in each module src/main/* from unit test code in src/test/*.
    In a typical multi-module projects like the one below:

    componentA
    |
    |-moduleA
    |         /src/main/java
    |         /src/main/resources
    |         /src/test/java
    |         /src/test/resources
    |-moduleB
    |         /src/main/java
    |         /src/main/resources
    |         /src/test/java
    |         /src/test/resources

    Note1: Eclipse do not support multi module project as only one level of code sharing is allowed. So we have
    3 eclipse projects/maven projects with a pom.xml:

    • componentA with a packaging pom, and 2 module aggregated
    • moduleA, parent is ../componentA/pom.xml
    • moduleB   parent is ../componentA/pom.xml

    Note2: eclipse has only one Class Loader, meaning that code in /src/main/java  and /src/test/java  is also exported
    as dependencies between modules, while in Maven, code is not shared!

    So as default by adding a dependencies in moduleB/pom.xml to moduleA, you'll only inherit moduleA src/main/java
    and src/main/resources

    <dependency>
    <groupId>com.waltercedric.maven</groupId>
    <groupId>modulesA</groupId>
    </dependency>

    But what if you have some test API classes in modulesA? trying to add also moduleA in scope test wont help you any further:

    <dependency>
    <groupId>com.waltercedric.maven</groupId>
    <artifactId>modulesA</artifactId>
    </dependency>
    
    <dependency> <!-- do not work! -->
    <groupId>com.waltercedric.maven</groupId>
    <artifactId>modulesA</artifactId>
    <scope>test</scope>
    </dependency>

    This is exactly where artifact classifier may help you, but lets first look at the artifact naming convention.

    artifact name = {name/artifactId}-{version}-{classifier}.{extension}

    Maven is also introducing some conventions:

    -> name is most of the time the artifactId
    -> version being the version number of the artifact, simply don't use something containing SNAPSHOTS 
        in it as it is considered being non stable by some plugin (maven-release-plugin for example) 
    -> classifier is either

    • empty like for ex: jaxb-1.2.jar and then it will contains the binary package of the library jaxb
    • source like for ex: jaxb-1.2-source.jar
    • javadoc like for ex: jaxb-1.2-javadoc.jar
    • but it can be anything! as it just classify an artifact, but don't use it in place where an artifact could
      have been use, a classifier proxy/stub is not recommended: make a module of it instead. You must see
      classifier more as a way to categorize artifact in a module.

    You'll find a lot of artifact across Internet not following these guidelines, this is not an issue as Maven repositories are
    able to search for pom.properties or project.xml or pom.xml in jar if they exist and use the right <groupId> and
    <artifactId>

    Back to code reuse of test classes across modules, the trick is to tell maven to make a jar of every module test code so
    you can depend on it in others modules.

    a normal build of componentA, would create:

    # /componentA/mvn clean install

    /.m2/repository/com/waltercedric/maven/moduleA/0.0.1.SNAPSHOTS/moduleA-0.0.1.SNAPSHOTS.jar
    /.m2/repository/com/waltercedric/maven/moduleB/0.0.1.SNAPSHOTS/moduleB-0.0.1.SNAPSHOTS.jar

    where by just adding to componentA/pom.xml the following inside the <build></build>:

    <!--  this create jar file of code from src/test/java so modules with tests can share code -->
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-jar-plugin</artifactId>
    <executions>
      <execution>
        <goals>
           <goal>test-jar</goal>
        </goals>
      </execution>
    </executions>
    </plugin>

    # /componentA/mvn clean install

    /.m2/repository/com/waltercedric/maven/moduleA/0.0.1.SNAPSHOTS/moduleA-0.0.1.SNAPSHOTS.jar
    /.m2/repository/com/waltercedric/maven/moduleA/0.0.1.SNAPSHOTS/moduleA-0.0.1.SNAPSHOTS-tests.jar
    /.m2/repository/com/waltercedric/maven/moduleB/0.0.1.SNAPSHOTS/moduleB-0.0.1.SNAPSHOTS.jar
    /.m2/repository/com/waltercedric/maven/moduleB/0.0.1.SNAPSHOTS/moduleB-0.0.1.SNAPSHOTS-tests.jar

    Maven now create new artifacts  moduleA-0.0.1.SNAPSHOTS-tests.jar!

    So you can now add a dependencies in moduleB/pom.xml to moduleA in scope test with a tests classifier

    <dependency> <!-- reuse src/main/java code from moduleA, normal dependencies --> 
    <groupId>com.waltercedric.maven</groupId> <artifactId>modulesA</artifactId> </dependency> <dependency> <!-- reuse src/test/java code from moduleA! --> <groupId>com.waltercedric.maven</groupId> <artifactId>modulesA</artifactId> <scope>test</scope> <classifier>tests</classifier> </dependency>

    You can now share test code across module.

    Related Posts

    relatedArticles

    Tags See All Tags Add New Tag...

    Please Enter New Tags Separated By Comma's
      Or Close

    apache  continuousbuild  framework  howto  maven 



    Comments
    Add New Search RSS
    +/-
    Write comment
    Name:
    Email:
     
    Website:
    Title:
    UBBCode:
    [b] [i] [u] [url] [quote] [code] [img] 
     
     
    :):grin;)8):p:roll:eek:upset:zzz:sigh:?:cry
    :(:x
     
    Please input the anti-spam code that you can read in the image.
    Connor  - great idea |67.176.44.xxx |2009-02-01 22:37:39
    Cedric, this is a great idea and works if you first do "mvn install" on
    the tests artifact.



    I have a multi-module project, with a parent POM and two children: Core and
    Website. Website depends on Core. When I run "mvn package" from the
    parent POM level, it compiles Core, and then when compiling the Website it
    automatically knows to use the Core snapshot that was just created (and not the
    older one in my repository).



    But when I run "mvn integration-test", it compiles Core, generates both
    the normal Core artifact and the Core tests artifact. But it doesn't
    automatically include the Core-1.0-SNAPSHOT-tests.jar when running the tests.
    Have you found a way around this? Maybe this is a Maven bug?
    Bo Gundersen  - same problme |77.243.62.xxx |2009-02-12 16:45:17
    Im having the same problem as you Conner. The proposed solution works greate if
    you do an "mvn install" in the parent, but if you do a "mvn
    test" it will break.
    Vincenzo Vitale  - Test jar included without the test scope |82.210.249.xxx |2009-04-15 10:28:22
    I have a submodule in which I want to include the test code of another module
    but not in the tests (than without the specifying the test scope). The intention
    is to execute the integration all the integration tests of the project in a web
    application.

    When I build from the root there is a compilation problem since the dependency
    is not correctly resolved. What's strange is that when I build the submodule
    everything is fine.

    It looks to me as a Maven bug (2.0.9).

    Thanks for the article,
    V.
    Vincenzo Vitale  - It was a bug [MNG-4032] |82.210.249.xxx |2009-04-15 10:36:12
    And actually it was a bug fixed in Maven 2.1.0

    Look here:
    http://jira.codehaus.org/browse/MNG-4032
    Dzmitry Lazerka |80.94.225.xxx |2009-05-10 11:49:19
    Thanks!
    CmaJ  - Great!!!! |88.16.30.xxx |2009-06-25 13:15:47
    Thanks!!!!!
    roger  - thanks! |216.49.181.xxx |2009-09-24 04:39:24
    Wow worked! Only gotcha is that you *have* to do a mvn install to get the test
    jar installed locally [i.e. you have to run the unit tests at least once].
    Cedric Walter |77.58.240.xxx |2009-09-24 13:07:06
    Yes

    if you start testcases using maven, a "clean install" is recommended.

    I recommend you to not run test cases in eclipse. If your company has the
    infrastructure... install a free edition of Teamcity and use private build
    (delayed commit) to run your testcases in teamcity continuous build server.

    I personnaly run testcase (sometimes) in eclipse, using the normal junit
    launcher. But as architecture evolved:
    * I just can't support all environment (tomcat, weblogic, jboss) on my developer
    machine
    * testcases need 15 minutes on a fast server
    * we have 56 maven modules and 1.5 millions LOC
    * a build agent validate a stack

    So I am more than happy to run them in a private build. If one or more tests are
    broken, I debug them in eclipse.
     

    Top 200 Tags

    Donation

    Thank You for supporting my work
    Click Here to make a donation