【问题标题】:Report is not generated, If I run my test cases(JUnit) through Maven?没有生成报告,如果我通过 Maven 运行我的测试用例(JUnit)?
【发布时间】:2014-05-19 07:33:55
【问题描述】:

我是 JUnit 和 Maven 的新手。我正在通过 Maven 运行我的 JUnit 测试用例。构建成功,但未生成 index.html。如何生成 index.html?

这是我构建成功后的项目结构。

而我的POM.xml如下,

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>MyGroup</groupId>
  <artifactId>TestCodeCoverage</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>MyMavenProject</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

<build>
<pluginManagement>
<plugins>
   <plugin>
    <groupId>org.jacoco</groupId>
    <artifactId>jacoco-maven-plugin</artifactId>
    <version>0.6.3.201306030806</version>
    <executions>
     <execution>
            <goals>
                <goal>prepare-agent</goal>
            </goals>
        </execution>
        <execution>
            <id>report</id>
            <phase>prepare-package</phase>
            <goals>
                <goal>report</goal>
            </goals>
        </execution>
    </executions>
   </plugin>
    <plugin>
        <inherited>true</inherited>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>2.3.2</version>
        <configuration>
           <encoding>UTF-8</encoding>
        </configuration>
    </plugin>
      <plugin>
      <artifactId>maven-failsafe-plugin</artifactId>
      <executions>
        <execution>
          <goals>
            <goal>integration-test</goal>
            <goal>verify</goal>
          </goals>
        </execution>
      </executions>
    </plugin>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.14.1</version>

        <dependencies>
     <dependency>
    <groupId>org.apache.maven.surefire</groupId>
      <artifactId>surefire-junit47</artifactId>
      <version>2.12</version>   
       </dependency>
    </dependencies>
     <configuration>                     
        <includes>
            <include>**/*.class</include>
         </includes>
        </configuration>    
      </plugin>
    </plugins>
   </pluginManagement>
  </build>

     <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>
     <dependency>
      <groupId>org.testng</groupId>
      <artifactId>testng</artifactId>
      <version>6.8</version>
    </dependency> 
    <dependency>
      <groupId>org.seleniumhq.selenium</groupId>
      <artifactId>selenium-server</artifactId>
      <version>2.41.0</version>
    </dependency>
    <dependency>
      <groupId>org.seleniumhq.selenium</groupId>
      <artifactId>selenium-java</artifactId>
      <version>2.41.0</version>
    </dependency>
  </dependencies>

  <dependencyManagement>
            <dependencies>
                <dependency>
                    <groupId>com.opera</groupId>
                    <artifactId>operadriver</artifactId>
                    <version>1.5</version>
                    <exclusions>
                        <exclusion>
                            <groupId>org.seleniumhq.selenium</groupId>
                            <artifactId>selenium-remote-driver</artifactId>
                        </exclusion>
                    </exclusions>
                </dependency>
            </dependencies>
 </dependencyManagement>

   <reporting>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-report-plugin</artifactId>
        <version>2.17</version>
        <reportSets>
          <reportSet>
            <id>integration-tests</id>
            <reports>
              <report>failsafe-report-only</report>
            </reports>
        </reportSet>
        </reportSets>
      </plugin>
    </plugins>
  </reporting>

</project>

【问题讨论】:

    标签: maven selenium junit selenium-webdriver pom.xml


    【解决方案1】:

    如果您希望 maven-surefire-report-plugin 生成报告,那么它会这样做,前提是您运行 site 目标 (mvn site)。否则,如您所见,reportstarget\surefire-reports 文件夹中可用。

    【讨论】:

    • 那么我需要更改我的 POM.xml 以查看 target\surefire-reports 文件夹中的报告。
    • 真的很抱歉,我听不懂。你能简单解释一下吗
    • 您应该在运行测试后运行站点目标。所以 mvn 测试站点应该可以解决问题。
    • 我试过了,但是我的maven安装路径在“C”目录,我的工作区目录在“E”目录。如何从“C”目录运行 mvn site 命令,该命令将引用位于“E:/TestProject/POM.xml”中的 POM.xml?请帮帮我
    • 有什么方法可以通过eclipse通过任何配置运行mvn站点吗?
    【解决方案2】:

    您应该导航到 pom.xml 所在的目录。使用此命令cd E:/TestProject,然后运行站点目标。例如mvn site

    【讨论】:

      猜你喜欢
      • 2015-12-20
      • 1970-01-01
      • 1970-01-01
      • 2017-05-19
      • 2014-09-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多