0

i am writing my first maven plugin and want to add unit tests for it. i read some about that and it seems that i need to extend AbstractMojoTestCase. But with this i only have JUnit3 style. Is there any way to use Junit4 (i want it mainly because of the "@Rule"s) probably in conjunction with mockito and/or guice (=juckito)?

At first step i need to inject @Parameter. i tried System.setProperty("some.prop", "someValue"); but this isn't working (parameter are null).

thx in advance

1 Answer 1

1

I haven't tried this, but I think the following approach would work. (I have used it with another library that had a similar problem.)

Step 1 - create a subclass of AbstractMojoTestCase

I know what you are thinking. This class has the same problem - that it is a JUnit 3.8 class. But that's ok. You aren't going to run it. All you are going to do is make public methods that you need to call. For example:

public org.codehaus.plexus.PlexusContainer getContainer() { return super.getContainer(); } 

Step 2 - write your JUnit 4 test

Write your Junit 4 test giving it a "helper" instance variable of the class in step 1. Have a @Before and @After method call the helper variable's setUp and tearDown methods.

Sign up to request clarification or add additional context in comments.

1 Comment

thx i'll try it. In my case i don't call any method of "AbstractMojoTestCase". all i need is the injection stuff that this class does. Something in AbstractMojoTestCase is injecting @Parameter annotated fields.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.