Reputation: 191
I have a maven mojo plugin with parameters like this:
public class SomeMojoPlugin
extends AbstractMojo
{
@Parameter( property = "templatefile", required = true )
private File templateFile;
And I want to write unit tests for this plugin. How to pass this property/parameter "templatefile" in test methods?
Upvotes: 2
Views: 686
Reputation: 19
@Parameter usually marks a class field. If it is protected or private and you want to get access to it, you can add a Setter like:
public void setTemplateFile(File templateFile) {
this.templateFile = templateFile;
}
If you use IntellijIDEA, just press Alt+Ins to create it easier...
Upvotes: 0
Reputation: 6302
The Maven documentation has a page about How To Use Maven Plugin Testing Harness.
Basically extending AbstractMojoTestCase, implementing the methods for the lifecycle and providing a sample pom.xml file for the test.
public class MyMojoTest extends AbstractMojoTestCase {
}
Upvotes: 1