【问题标题】:Report not being generated with Maven-Surefire-Report plugin没有使用 Maven-Surefire-Report 插件生成报告
【发布时间】:2017-02-05 09:54:03
【问题描述】:

正如标题所示,我正在尝试在我的 maven 项目执行时生成 JUnit 结果的 HTML 报告。有人告诉我要检查另一个人的 maven-surefire-report 插件,它看起来有我想要的东西,但我似乎无法生成 HTML 文件。我希望只生成一个 HTML 文件,然后我可以将其放入我的老板的电子邮件中。我真的不想将结果发布到网站上(至少目前不是)。

这是我的 pom 部分的外观(不用担心缺少标签。我正在复制和粘贴相关部分,并尽量不粘贴公司信息,但知道我有正确的开始/结束标签):

编辑:添加完整的 pom。

<?xml version="1.0" encoding="UTF-8"?>
<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>myArtifact</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>myName</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.4.0.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <!-- https://mvnrepository.com/artifact/net.sourceforge.jtds/jtds -->
        <dependency>
            <groupId>net.sourceforge.jtds</groupId>
            <artifactId>jtds</artifactId>
            <version>1.3.1</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-test -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <version>1.4.0.RELEASE</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-configuration-processor</artifactId>
            <optional>true</optional>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.springframework/spring-context -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>4.3.2.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjweaver</artifactId>
            <version>1.6.5</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.springframework/spring-beans -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
            <version>4.3.2.RELEASE</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-core -->
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-core</artifactId>
            <version>2.6.2</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>RELEASE</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind -->
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.0.2</version>
        </dependency>

        <dependency>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-report-plugin</artifactId>
            <version>2.19.1</version>
            <type>maven-plugin</type>
        </dependency>

        <dependency>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.19.1</version>
            <type>maven-plugin</type>
        </dependency>
    </dependencies>

    <reporting>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-report-plugin</artifactId>
                <version>2.19.1</version>
            </plugin>

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

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-site-plugin</artifactId>
                <version>3.5.1</version>
                <configuration>
                    <outputDirectory>${basedir}/target/site/surefire-report.html</outputDirectory>
                </configuration>
                <!--<configuration>-->
                    <!--<outputDirectory>C:\Users\ab66378\Desktop</outputDirectory>-->
                <!--</configuration>-->
            </plugin>
        </plugins>
    </reporting>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>


</project>

据我所知,根据指南和我没有看过的内容,这就是我所需要的。只是 pom 依赖项和报告插件部分,但我仍然没有看到生成的 HTML 文件。

我有一种感觉,我缺少的部分将非常少,但我似乎无法找到它。

【问题讨论】:

  • 您是否生成了目标输出文件?应该在某个地方。如果没有,那么可能是您没有为报告配置输出目录。
  • 我确实尝试过一点输出目录,但我仍然找不到任何东西。我首先尝试将输出添加到桌面,以便查看它是否正常工作。这是它的样子:C:\Users\username\Desktop

标签: java maven pom.xml maven-surefire-plugin


【解决方案1】:

默认报告应位于 ${basedir}/target/site/surefire-report.html

我相信您可能需要分别在插件/依赖项中包含 maven-surefire-plugin 和 junit。

surefire 报告插件将自动解析 ${basedir}/target/surefire-reports 中与 TEST-.xml 匹配的文件,但我相信您需要 maven-surefire-plugin 才能生成 TEST-.xml 文件

这是插件的文档。一种方法可能是运行构建并查看是否正在生成 TEST-*.xml 文件。

http://maven.apache.org/surefire/maven-surefire-plugin/index.html

【讨论】:

  • 非常感谢丹的回复。这是让我感到困惑的部分,我敢肯定这是因为我以前没有大量的经验来设置这样的东西。我是真的写 ${basedir} 还是只是我自己硬编码的目录的占位符。我没有太多处理路径和创建文件的经验,所以它可能会作为一个新手问题出现:)
  • ${baseDir} 是你 pom 所在的director。你可以输入它,maven 会解决它
  • 如果您仍然有问题发布整个 pom 可能有助于进一步确定问题
  • 好的,所以我将 maven-surefire-plugin 依赖项和插件添加到 pom.xml 中。我已经在 pom 的顶部有 JUnit 依赖项。当我执行我的测试时,它甚至看起来不像是在“目标”下创建了“站点”文件夹。
  • 我在这里创建了一个要点gist.github.com/dwdking/eface84d904fc4dc2c51015b1d7e1958,如果我进行 mvn clean verify 它对我有用,主要的变化是我在 build/plugins 中包含了 surefire 报告插件并添加了执行部分。此执行可能包含在您的万无一失报告插件的报告/插件部分中,但我不肯定
【解决方案2】:

如下配置

<configuration>
<outputDirectory>${basedir}/target/newsite</outputDirectory>
</configuration>

使用独立工具,您可以更改路径,如下所示

mvn surefire-report:report -DoutputDirectory=newpath

【讨论】:

    【解决方案3】:

    默认情况下,surfire 插件将在{base-dir}/target/surfire-reports 中创建 XML 和 txt 文件报告。 生成 HTML 报告,您可以使用

    mvn surefire-report:report-only
    

    上述命令将使用 XML 文件并在 {base-dir/target/site/surefire-report.html} 处创建 HTML 报告

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-11-19
      • 1970-01-01
      • 1970-01-01
      • 2018-09-05
      • 2014-12-01
      • 2014-07-02
      • 2023-03-21
      相关资源
      最近更新 更多