Unit testing (junit4) maven plugins

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

In the first step, I need to enter @Parameter . I tried System.setProperty("some.prop", "someValue"); but this does not work (parameter is null).

thanks in advance

0
source share
1 answer

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

Step 1 - Subclass AbstractMojoTestCase

I know what you are thinking. This class has the same problem as the JUnit 3.8 class. But it normal. You are not going to run it. All you are going to do is make the public methods you need to call. For instance:

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

Step 2 - write your JUnit 4 test

Write your Junit 4 test, giving it the "helper" class instance variable in step 1. If the @Before and @After methods call the setUp and tearDown helper methods.

+1
source

Source: https://habr.com/ru/post/957041/


All Articles