使用maven-surefire-plugin将测试报告发送到不同的目录

Ami*_*nai 0 junit maven-plugin maven-3

我想生成我的报告所以我用过maven-surefire-plugin.

这是我的pom.xml:

<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.10</version>
<executions> 
<execution> 
 <id>test-reports</id> 
    <phase>install</phase> 
    <configuration> 
      <tasks> 
<junitreport todir="./reports">
<fileset dir="./reports">
<include name="TEST-*.xml"/>
</fileset>
<report format="frames" todir="./report/html"/>
</junitreport>
</tasks> 
    </configuration> 
    <goals> 
      <goal>test </goal> 
    </goals> 
  </execution> 
</executions> 
</plugin>
Run Code Online (Sandbox Code Playgroud)

但是当我运行maven测试时,我收到了这个错误:

 Tests run: 6, Failures: 2, Errors: 2, Skipped: 0
 [INFO] --------------------------------------------------------------------
 [INFO] BUILD FAILURE
 [INFO] --------------------------------------------------------------------
 [INFO] Total time: 10.403s
 [INFO] Finished at: Wed Oct 12 08:35:10 CEST 2011
 [INFO] Final Memory: 17M/126M
 [INFO] --------------------------------------------------------------------
 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-      plugin:2.10:test (default-test) on project jebouquine: There are test failures.
 [ERROR] 
 [ERROR] Please refer to C:\Users\Amira\workspace1\jebouquine\target\surefire-reports for the individual test results.
 [ERROR] -> [Help 1]
 [ERROR] 
 [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
 [ERROR] Re-run Maven using the -X switch to enable full debug logging.
 [ERROR] 
 [ERROR] For more information about the errors and possible solutions, please read the following articles:
 [ERROR] [Help 1]       http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
Run Code Online (Sandbox Code Playgroud)

当我打开 C:\Users\Amira\workspace1\jebouquine\target\surefire-reports我发现repotrts但我想要他们./reports.

知道怎么做吗?或者有没有其他方法来生成我的测试报告?

Zac*_*son 6

看,这是底线:你需要阅读更多关于Maven的内容,因为你所写的内容没有意义.您已尝试将ant配置元素填充到surefire插件配置中,这根本不对.并且您已尝试将其绑定到安装阶段,但随后您正在运行mvn test.

最后,如果您首先在不同的目录中解释了为什么要将它们放在另一个目录中,它可能会有所帮助......可能有更好的方法来实现您的真正目标.

但是,这将在接下来的5秒左右解决您的问题:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <version>2.10</version>
  <configuration>
    <reportsDirectory>${project.build.directory}/reports</reportsDirectory>
  </configuration> 
</plugin>
Run Code Online (Sandbox Code Playgroud)