让我们想象一下我跟随mojo:
@Mojo(name = "some-goal")
public class MyMojo {
@Parameter(required = true)
protected ComplexObject param;
/*...*/
}
此外,我在pom中有插件的描述符:
<plugin>
<!-- here artifact description -->
<executions>
<execution>
<phase>...</phase>
<goals><goal>some-goal</goal></goals>
<configuration>
<param>...</param>
</configuration>
</execution>
</executions>
</plugin>
为了测试这个插件我使用 maven-plugin-testing-harness
我的测试代码是:
@Test
public void test() throws Exception {
File pom = getFile("mix/pom.xml");
MyMojo plugin = (MyMojo) rule.lookupMojo("some-goal", pom);
/*....*/
}
规则是:
@Rule
public MojoRule rule = new MojoRule() {
@Override
protected void before() throws Throwable {
}
@Override
protected void after() {
}
};
但是当我运行测试时,它失败并出现异常:
org.apache.maven.plugin.testing.ConfigurationException:无法为artifactId为{plugin-name}的插件找到配置元素。
at org.apache.maven.plugin.testing.AbstractMojoTestCase.extractPluginConfiguration(AbstractMojoTestCase.java:619)
at org.apache.maven.plugin.testing.AbstractMojoTestCase.extractPluginConfiguration(AbstractMojoTestCase.java:582)
at org.apache.maven.plugin.testing.AbstractMojoTestCase.lookupMojo(AbstractMojoTestCase.java:353)
at org.apache.maven.plugin.testing.MojoRule.lookupMojo(MojoRule.java:164)
当我调试 maven-plugin-testing-harness 的源代码时,我注意到它只从root插件元素读取配置。
如何强制它从执行元素读取配置?
答案 0 :(得分:5)
添加空public class FilteringPage extends PageObject {
public FilteringPage(WebDriver driver) {
super(driver);
}
public FilterBlock filterBlock;
}
public class FilterBlockSteps extends ScenarioSteps {
public FilterBlockSteps(Pages pages){
super(pages);
}
private FilteringPage onFilteringPage(){
return pages().get(FilteringPage.class);
}
@Step("Ввод начальной цены {0}")
public void setFilterStartPrice(String price) {
onFilteringPage().filterBlock.priceFrom.sendKeys(price);
}
@Step("Ввод конечной цены {0}")
public void setFilterFinishPrice(String price) {
onFilteringPage().filterBlock.priceTo.sendKeys(price);
}
@StepGroup
public void filtering(String priceFrom, String priceTo){
setFilterStartPrice(priceFrom);
setFilterFinishPrice(priceTo);
}
}
块以测试插件配置对我有帮助。
尝试使用这些代码:
<configuration></configuration>
Maven插件测试没有很好地描述并且看起来有些错误......
答案 1 :(得分:0)
有两种方法可以解决此问题。
将来电lookupMojo("some-goal", pom)
更改为lookupEmptyMojo("some-goal", pom)
或在build -> plugins -> plugin
内添加一个空的<configuration></configuration>
部分。
<plugin>
<!-- here artifact description -->
<configuration></configuration>
<executions>
<execution>
<phase>...</phase>
<goals><goal>some-goal</goal></goals>
<configuration>
<param>...</param>
</configuration>
</execution>
</executions>
</plugin>
答案 2 :(得分:0)
您如何指定零件
df1 = df1.reset_index()
df1['Month Name']=df1['month'].apply(lambda x:calendar.month_abbr[x])
您是否指定了插件的groupId和artifactId?如果不是这种情况,则不使用配置部分。这可能与原型产生的不完全正确(https://issues.apache.org/jira/projects/MARCHETYPES/issues/MARCHETYPES-67?filter=allopenissues)
有关