Sie müssen die maven-plugin-testing-harness ,
<dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-plugin-testing-harness</artifactId>
<version>1.1</version>
<scope>test</scope>
</dependency>
Sie leiten Ihre Unit-Test-Klassen ab von AbstractMojoTestCase .
Sie müssen ein einfaches POM erstellen, normalerweise in der src/test/resources
Ordner.
<project>
<build>
<plugins>
<plugin>
<groupId>com.mydomain,mytools</groupId>
<artifactId>mytool-maven-plugin</artifactId>
<configuration>
<!-- Insert configuration settings here -->
</configuration>
<executions>
<execution>
<goals>
<goal>mygoal</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Verwenden Sie AbstractMojoTest.lookupMojo(String,File) (oder eine der anderen Varianten), um das Mojo für ein bestimmtes Ziel zu laden und auszuführen.
final File testPom = new File(PlexusTestCase.getBasedir(), "/target/test-classes/mytools-plugin-config.xml");
Mojo mojo = this.lookupMojo("mygoal", testPom);
// Insert assertions to validate that your plugin was initialised correctly
mojo.execute();
// Insert assertions to validate that your plugin behaved as expected
Ich habe ein eigenes Plugin erstellt, auf das Sie sich zur Klärung beziehen können http://ldap-plugin.btmatthews.com ,