How to populate parameter “defaultValue” in Maven “AbstractMojoTestCase”?

一笑奈何 提交于 2019-12-04 07:35:51

You need to use lookupConfiguredMojo.

Here's what I ended up using:

public class MyPluginTest
{    
    @Rule
    public MojoRule mojoRule = new MojoRule();

    @Test
    public void noSource() throws Exception
    {
        MyPlugin plugin = (MyPlugin) mojoRule.lookupConfiguredMojo(loadPom("testpom1"), "myGoal");
        plugin.execute();

        assertThat(plugin.getSomeInformation()).isEmpty();
    }

    public File loadPom(String folderName)
    {
        return new File("src/test/resources/", folderName);
    }
}

Of course you need to replace myGoal with your plugin's goal. You also need to figure out how to assert that your plugin executed successfully.

For a more complete example, check out the tests I wrote for fmt-maven-plugin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!