我们可以在执行maven-surefire-plugin之前执行exec-maven-plugin吗? [英] Can we execute exec-maven-plugin before maven-surefire-plugin?
问题描述
是否有可能在maven-surefire-plugin之前运行exec-maven-plugin,我在运行过程中观察到的是maven-surefire-plugin首先执行,即使标记中的顺序是第二个.我的场景是执行JAVA CLASS(使用exec-maven-plugin),该类生成我的testng.xml并可以使用(maven-surefire-plugin)运行它.
Is it possible to run exec-maven-plugin before maven-surefire-plugin, what I observe during my run is maven-surefire-plugin is executing first even though the sequence in tag is second. My scenario is to execute JAVA CLASS (using exec-maven-plugin ) which generates my testng.xml and can run that using (maven-surefire-plugin).
推荐答案
首先,如果您执行了绑定到test
阶段的exec-maven-plugin
,则通常在执行后执行该操作maven-surefire-plugin
的.原因是您可能正在处理打包jar
,
First of all, if you have an execution of the exec-maven-plugin
bound to the test
phase, it is normal that this execution is performed after the one of the maven-surefire-plugin
. The reason is that you're likely dealing with a project of packaging jar
, which has a default binding of the Surefire Plugin to the test
phase. This default execution is always the first one invoked, regardless of where the plugin is declared in the POM. In the logs, you will spot this execution with an id of default-test
.
There is a way to perform actions before the tests are run by leveraging the phases invoked before the phase test
. In your case, your goal is to generate a test resource, the testng.xml
, so it would be appropriate to use the generate-test-resources
phase, whose purpose is to create resources that are needed for the tests. Therefore, you just need to specify
<phase>generate-test-resources</phase>
执行exec-maven-plugin
生成testng.xml
.
然后,您可以将生成的testng.xml
与使用Suite XML文件
Then, you can use the generated testng.xml
with the suiteXmlFiles
element, see Using Suite XML Files
这篇关于我们可以在执行maven-surefire-plugin之前执行exec-maven-plugin吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!