使用不同的参数两次执行Maven-surefire-plugin

use*_*047 0 unit-testing surefire maven

我正在尝试通过带有两个不同参数的sure-fire插件运行我的单元测试。一种是使用jacoco将测试结果输入SonarQube,另一种是使用dynatrace运行。我尝试将其放在两个不同的执行标签中,但似乎无法正常工作。请问我做错了什么?以下是我的pom.xml的片段:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <version>2.12</version>
  <configuration>
     <argLine>${jacoco.ut.arg}</argLine>
     <argLine>-agentpath:"C:\Program Files\dynaTrace\Dynatrace 6.3\agent\lib64\dtagent.dll"=name=JavaAgent,server=localhost:9998,optionTestRunIdJava=${dtTestrunID}</argLine>
     <excludes>
       <exclude>**/at/**</exclude>
       <exclude>**/it/**</exclude>
     </excludes>
   </configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)

car*_*ing 5

您需要使用<executions/>。考虑以下示例:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.12</version>

    <!-- You could also have the configuration tag inside the execution -->
    <configuration>
        <argLine>${jacoco.ut.arg}</argLine>
        <argLine>-agentpath:"C:\Program Files\dynaTrace\Dynatrace 6.3\agent\lib64\dtagent.dll"=name=JavaAgent,server=localhost:9998,optionTestRunIdJava=${dtTestrunID}</argLine>
        <excludes>
            <exclude>**/at/**</exclude>
            <exclude>**/it/**</exclude>
        </excludes>
    </configuration>

    <executions>
         <execution>
             <id>run-tests</id>
             <phase>test</phase>   <!-- or whatever phase you like -->
             ...
         </execution>
         <execution>
             <id>run-jacoco</id>
             <phase>test</phase>   <!-- or whatever phase you like -->
             <goals>...</goals>
             ...
         </execution>
    </executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)

看看Maven POM参考

执行:记住一个插件可能有多个目标,这一点很重要。每个目标可能具有单独的配置,甚至可能将插件的目标完全绑定到不同的阶段。执行配置插件目标的执行。