Getting started with Maven plugin testing
I'm writing a very simple Maven plugin, and I am kind of lost with the testing part. Based on the plugin developers site, there are several different tools to achieve the same things, which 开发者_JAVA百科documentation seem outdated... I found resources like this too, and took a look at the "core" plugins, but this is still very unclear to me.
As there does not seem to be one solution for this, I am asking for your personal experience here.
I don't have much to add to the Review of Plugin Testing Strategies page which is pretty exhaustive and it really depends on the kind of tests you want to write.
But since you're asking for practical feedback my recommendation would be to write both unit tests and integration tests, the later being extremely important when plugins (if you want to skip something, don't skip integration tests).
For Unit Tests, use the maven-plugin-testing-harness. check the Maven Plugin Harness Wiki and existing plugins like the maven-compiler-plugin (see the CompilerMojoTestCase
).
For integration tests, I suggest to use the maven-invoker-plugin and/or the shitty-maven-plugin. They're similar but still have slight differences so you might prefer one over the other depending on the situation. Refer to the matrix for the details.
See also
- unit-testing maven plugins
Take the Perl's advice - there's always more than one way to do it.
It really depends on the scope of your test. If you are testing against simply just the logic, a basic JUnit test case will do; If you are performing mock tests or integration tests with some contexts needed and you simply do not want to redo what people have done, the Maven's page has explained how these different techniques shall be applied.
精彩评论