Hello everyone,

found a solution by using the MojoRule class in my test:

@Rule
public MojoRule mojoRule = new MojoRule(this);

My test is still a sub-class of AbstractMojoTestCase.
The execution  of my plugin within the test works like this:

this.mojoRule.executeMojo(basedir, "plugin-name");

"basedir" is of type java.io.File and points to the folder in which the example 
pom.xml resides.
"plugin-name" is the name of the plugin without the "-maven-plugin" suffix.

Maybe this will help some others of you who face the same problem.
I don't know if there is a more straight-forward method like this...

Regards,
Gerrit

-----Ursprüngliche Nachricht-----
Von: Hohl, Gerrit [mailto:g.h...@aurenz.de] 
Gesendet: Dienstag, 3. Mai 2016 11:48
An: users@maven.apache.org
Betreff: JUnit tests for Maven plugin and Java annotations

Hello everyone,

 

I'm currently writing a Maven plugin and I want to have some JUnit tests
for it.

The artifact maven-plugin-testing-harness offers an environment through
its AbstractMojoTestCase class.

After reading half of the Internet I also got it working.

But now I'm stuck as it seems to ignore the annotation of my plugin.

I used the Java annotations provided by the artifact
maven-plugin-annotations.

In the META-INF/maven/plugin.xml I see all the parameters.

But when I execute my JUnit test case - which is sub-class of the
AbstractMojoTestCase - I get null for all of these properties.

One example for these properties of my plugin:

 

@Parameter(defaultValue="${project}", readonly=true)

private MavenProject project;

 

Does AbstractMojoTestCase not supported Java annotations and also not
read it from the plugin.xml?

At least from the plugin.xml it should be able to read it, I think,
because it throws an exception if that file doesn't exist.

Or do I have to take some extra steps (e.g. method calls of
AbstractMojoTestCase) to get them set?

 

Regards

Gerrit

 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@maven.apache.org
For additional commands, e-mail: users-h...@maven.apache.org

Reply via email to