updating this thread again

Jason and I talked over the above idea and he took a few minutes and put
together the basic jist of the concept and shoved it into the mojo-sandbox
so I could work with it.

mojo-sandbox/maven-plugin-testing/maven-plugin-testing-harness

that has version 1.0-SNAPSHOT of the AbstractMojoTestCase which is what the
test cases can subclass from to get the ability to dynamically load the mojo
based on an arbitary pom.

I modified the maven-clean-plugin again to make use of this and it turned
out quite well I'd say.

   /**
     * tests the ability of the plugin to clean out a set of directories
     *
     * @throws Exception
     */
    public void testClean() throws Exception {

        CleanMojo mojo = (CleanMojo) lookupMojo ("clean", testPom );

        assertNotNull( mojo );

        mojo.execute();

        assertFalse ( FileUtils.fileExists(
"target/test/testDirectoryStructure/buildDirectory" ) );
        assertFalse ( FileUtils.fileExists(
"target/test/testDirectoryStructure/buildOutputDirectory" ) );
        assertFalse ( FileUtils.fileExists(
"target/test/testDirectoryStructure/buildTestDirectory" ) );
    }


This method in the CleanMojoTest class coupled with this pom.xml @
src/test/resources/unit/clean/pom.xml execute the unit test very easily.

<project>
  <build>
    <plugins>
      <plugin>
        <artifactId>maven-clean-plugin</artifactId>
        <configuration>

<directory>target/test/testDirectoryStructure/buildDirectory</directory>

<outputDirectory>target/test/testDirectoryStructure/buildOutputDirectory</outputDirectory>

<testOutputDirectory>target/test/testDirectoryStructure/buildTestDirectory</testOutputDirectory>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

I am going to take this approach and work on testing another plugin in maven
now, get a couple of plugins under my belt with this and the abstract base
class ought to be pretty tight.

jesse

--
jesse mcconnell
jesseDOTmcconnellATgmailDOTcom

Reply via email to