java - How do you create automated tests of a Maven plugin using JUnit? -


i've got (mostly) working plugin developed, since function directly related project processes, how develop unit , integration tests plugin. best idea i've had create integration test project plugin uses plugin during lifecycle , has tests report on plugins success or failure in processing data.

anyone better ideas?

you need use 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> 

you derive unit test classes abstractmojotestcase.

you need create bare bones pom, in src/test/resources folder.

     <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> 

use abstractmojotest.lookupmojo(string,file) (or 1 of other variations) load mojo specific goal , execute it.

     final file testpom = new file(plexustestcase.getbasedir(), "/target/test-classes/mytools-plugin-config.xml");     mojo mojo = this.lookupmojo("mygoal", testpom);     // insert assertions validate plugin initialised correctly     mojo.execute();     // insert assertions validate plugin behaved expected 

i created plugin of own can refer clarification http://ldap-plugin.btmatthews.com,


Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -