You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by John Fallows <jo...@gmail.com> on 2005/09/08 23:14:23 UTC

[m2] plugin tests?

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: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: [m2] plugin tests?

Posted by Brett Porter <br...@gmail.com>.
Hi John,

Good idea. Currently we were expecting people to add setters and test as a 
conventional bean, but this could certainly be helpful. The code that does 
the populate in DefaultPluginManager is not very much as it mostly calls out 
to plexus, so perhaps that can be abstracted out.

- Brett

On 9/9/05, John Fallows <jo...@gmail.com> wrote:
> 
> 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
> mojo.execute();
> 
> // 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 <fo...@neonics.com> 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: users-unsubscribe@maven.apache.org
> > > For additional commands, e-mail: users-help@maven.apache.org
> > >
> > >
> >
> > --
> > Kenney Westerhof
> > http://www.neonics.com
> > GPG public key: http://www.gods.nl/~forge/kenneyw.key
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> > For additional commands, e-mail: users-help@maven.apache.org
> >
> >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
> 
>

Re: [m2] plugin tests?

Posted by John Fallows <jo...@gmail.com>.
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
    mojo.execute();

    // 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 <fo...@neonics.com> 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: users-unsubscribe@maven.apache.org
> > For additional commands, e-mail: users-help@maven.apache.org
> >
> >
> 
> --
> Kenney Westerhof
> http://www.neonics.com
> GPG public key: http://www.gods.nl/~forge/kenneyw.key
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
> 
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: [m2] plugin tests?

Posted by Kenney Westerhof <fo...@neonics.com>.
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: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>

--
Kenney Westerhof
http://www.neonics.com
GPG public key: http://www.gods.nl/~forge/kenneyw.key

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org