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

 

Reply via email to