【发布时间】:2022-02-08 21:43:04
【问题描述】:
这是我的测试(maven-plugin-testing-harness 3.3.0,junit 5.6.2):
import java.io.File;
import org.apache.maven.plugin.testing.AbstractMojoTestCase;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
public final class MyMojoTest extends AbstractMojoTestCase {
@BeforeEach
public void setup() throws Exception {
this.setUp();
}
@Test
public void executeIt() throws Exception {
final File pom = new File("src/test/resources/my-test-pom.xml");
final MyMojo mojo = MyMojo.class.cast(
this.lookupMojo("mygoal", pom)
);
mojo.execute();
}
}
这就是我在MyMojo (maven-plugin-api 3.8.4) 中所拥有的:
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
@Mojo(name = "my", defaultPhase = LifecyclePhase.COMPILE)
public final class MyMojo extends AbstractMojo {
@Parameter(defaultValue = "${project}", readonly = true)
private MavenProject project;
}
问题是lookupMojo()返回的mojo没有project属性集(它是null)。
提出了一些解决方案here,但我不确定它如何与 JUnit 5 一起使用。
【问题讨论】: