Hi,

I had the same Problem and so I tried to use the Maven embedder, so the whole Plexus variable injection thing takes place, but unfortunately I did not manage to execute it successfully (I don't how mature the embedder is).
Take a look: http://maven.apache.org/guides/mini/guide-embedding-m2.html

Michael Böckling


Hi,



  I would like to unit test my MOJO (Maven2 plugin).  I could add a
setter for each private instance variable, but I would like to have them
injected (like when they run).  What is the recommended way to unit test
MOJOs?





public class Instr extends AbstractMojo {

           /**

            * The artifact id

            * @parameter expression="${project.artifactId}"

            */

           private String artifactId;



           /**

            * The version

            * @parameter expression="${project.version}"

            */

           private String version;



           /**

            * The version

            * @parameter expression="${project.build.outputDirectory}"

            */

           private String outputDir;

...





public class InstrTest {

...

           public final void testExecute() {

                       try {

                                   instr.execute();

                       } catch (MojoExecutionException e) {

                                   Assert.fail("Not expecting a
MojoExecutionException", e);

                       } catch (MojoFailureException e) {

                                   Assert.fail("Not expecting a
MojoFailureException", e);

                       }

           }

...



Thank you, Michael


--
Giniality AG - Michael Böckling; Steinenberg 21, CH-4051 Basel
P: +41 61 226 99 63 - F: +41 61 226 99 69
[EMAIL PROTECTED]; http://www.giniality.com/



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to