Spent some time playing around with JUnit 4.x and mojo development.  I'm 
posting to share the experiment and see if what I've found out is correct or 
not so here goes...


        1. If you are using easymock, make sure you are using 
http://repo2.maven.org/maven2/org/easymock/easymock/, and not 
http://repo2.maven.org/maven2/easymock/easymock/.  Easymock moved at some point
        2. Bump your pom's dependencies to use easymock 2.5.2 and junit 4.7.  
This will require overloading these two dependencies listed in mojo-parent
        3. Specify this property to update your JDK 
<project.build.java.target>1.6</project.build.java.target>.  JDK 1.5 works as 
well.

        4. Rewrite some of your tests using Junit 4 syntax as needed.  No need 
to rewrite everything.  Biggest gotcha is you can't extend "TestCase" like you 
could in Junit 3.x.   Junit will put you back into Junit 3.x syntax when it 
sees this!

        5. Biggest bummer is you can't extend PlexusTestCase, it extends 
TestCase
        6. I've tried this on maven 2.2 and 3.0-alpha-5 and should work with 
most 2.x versions I would think

        7. Put this test into one of your Junit 4 tests to make sure the 
annotations are working.
    // Test Junit 4.x setup
    @org.junit.Test(expected=ArithmeticException.class) public void 
testDivideByZero()
    {
        int n = 2 / 0;
    }


That test will fail if you are in Junit 3.x mode and blow your build up if 
something isn't setup right.

I've put a enhancement request into plexus for a PlexusTester abstract class 
which would support Junit 4.x because not having the component support in 
PlexusTestCase is a drag.  http://jira.codehaus.org/browse/PLX-446.  I'm going 
to have a CbuildPlexusTester for the stuff I'm working on for the time being 
and go to Junit 4.7

Reply via email to