【发布时间】:2014-01-26 20:44:45
【问题描述】:
TL;DR:使用 maven,我想在测试实际运行之前在 test 阶段开始时运行插件目标。什么是干净的方法?
我想在测试实际运行之前打印一条消息。因此,我想在测试阶段开始时使用echo plugin 的echo 目标(告诉用户如果每个测试都失败,他最好看看README,因为有一个测试环境他应该先设置)
第 1 次尝试
一种简单的方法是在the previous phase、process-test-classes 中运行此插件。
它可以工作,但是将此任务绑定到此阶段在语义上似乎不正确...
第 2 次尝试
根据Maven documentation,When multiple executions are given that match a particular phase, they are executed in the order specified in the POM, with inherited executions running first.,所以我尝试明确设置surefire插件:
...
<plugin>
<groupId>com.soebes.maven.plugins</groupId>
<artifactId>maven-echo-plugin</artifactId>
<version>0.1</version>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>echo</goal>
</goals>
</execution>
</executions>
<configuration>
<echos>
<echo>*** If most tests fail, make sure you've installed the fake wiki. See README for more info ***</echo>
</echos>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.16</version>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
...
但测试会在我的消息打印之前运行。
所以,简而言之:有没有办法达到我的目标,还是我应该坚持“process-test-classes 解决方案”,即使它看起来有点“hacky”?
谢谢!
【问题讨论】:
-
在测试之前检查一下假维基的存在不是更好吗?除此之外,这听起来像是在运行集成测试而不是单元测试。
标签: maven maven-plugin