maven-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From John Fallows <>
Subject Re: [m2] plugin tests?
Date Thu, 08 Sep 2005 23:55:02 GMT
Hey Kenny,

I'm looking for something more like a unit test than an integration
test, such as:

public class MyMojoTest extends MojoTestCase
  public void testMojo() throws MojoExecutionException
    // create mojo, with default property values
    Mojo mojo = createMojo(...);

    // override certain mojo properties (optional)
    setMojoProperty(mojo, "propertyName", ...);

    // execute mojo

    // check results for this particular test

The goal is to verify that this single Mojo class behaves as expected,
but it is not important to be running in the real M2 runtime. 
However, since M2 runtime generally takes responsibility for
instantiation, configuration and execution of plugins, this needs to
be simulated for a unit test environment.

Is this a reasonable approach to M2 plugin testing, or is it better to
only test them using integration tests in the real M2 runtime?

Kind Regards,
John Fallows.

On 9/8/05, Kenney Westerhof <> wrote:
> On Thu, 8 Sep 2005, John Fallows wrote:
> You could try out the maven-it-plugin in the sandbox, if you're using
> svn head.
> Just place test projects in src/it/ and bind the maven-it-plugin
> to a phase after 'install', using the 'fork' goal.
> Unfortunately to be able to test a plugin it needs to be installed
> for maven to find it. I'm working on a way to let maven find and use that
> plugin so it doesn't need to be installed (it might already work since
> the 'current' project is in the reactor. You'd have to specify
> a dependency on it in the test project too, I think).
> As you can see it's not finished yet, so if you feel like
> experimenting, you're welcome.
> If not, take a look at the maven-eclipse-plugin. The JUnit tests
> 'fake' being maven, loading a fake pom, manually instantiating the
> Mojo, and using setter methods to fill in the parameters,
> and call the execute() method. I'm hoping to provide a general
> plugin testing framework (read: plugin :)) in maven-it-plugin
> so this 'hacking' isn't necessary.
> -- Kenney
> > What is the recommended approach for testing m2 plugin Java code?
> >
> > I would like to be able to write a JUnit test, but need to simulate
> > the bootstrap process of initializing the various properties to their
> > defaults, and possibly setting some non-default parameter values, all
> > before Mojo.execute() is called.
> >
> > Is there any existing solution for this?  Perhaps a reusable JUnit
> > TestCase base class that could be extended?
> >
> > Thanks in advance,
> > John Fallows.
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> > For additional commands, e-mail:
> >
> >
> --
> Kenney Westerhof
> GPG public key:
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message