views:

47

answers:

2

Hi,

I'm looking for information about how to write unit tests for Maven plugins. Although there's a page on the Maven site about this topic, there's only one example unit test, which does nothing useful. I also found this wiki page, but it hasn't been updated for more than 4 years, so I'm reluctant to invest any faith in it.

I checked the book "The Definitive Guide to Maven", but it doesn't even mention the subject. I'd like to write my unit tests in either Groovy or Java, and would appreciate any information about how to do this.

I'm using Maven version 2.1.0.

Thanks, Don

+1  A: 

If you really do Unit Tests in your plugin the first link is the right one. But it depends a little bit what you like to test here. The functionality of the implementation or in combination with Maven? But i made the experience that it might be better to do some kind of integration tests instead for Plugins. For this purpose you should take a deep look into the Maven Invoker Plugin which can help your very good. May you should take a look at the other plugins which existing how they do there testing.

khmarbaise
+1  A: 

The first link you posted is the right place to learn about the various possibilities and to start with. But for examples, the best thing to do would be to look at the sources of existing plugins. Having that said:

For unit testing, my preference goes to the maven-plugin-testing-harness. You can learn (a bit) more about it in the Maven Plugin Harness Wiki but, as I said, especially in plugins using it, for example the maven-compiler-plugin. Check the CompilerMojoTestCase.

For integration testing (it's IMO very important for plugins to do integration testing), I'd recommend the shitty-maven-plugin (Super Helpful Integration Testing ThingY), especially if you are interested by writing tests in Groov, or the maven-invoker-plugin. They are similar but have both features that the other doesn't. The website of the SHITTY plugin mentions several plugins using it. Check it out.

Pascal Thivent