小编Joh*_*ohn的帖子

JaCoCo 报告生成出错

我目前正在尝试将 JaCoCo 添加为我的 Spring Boot maven 项目的依赖项,以查看我的单元测试的代码覆盖率。但是,当我运行测试时,它失败并显示错误。

 Failed to execute goal org.jacoco:jacoco-maven-plugin:0.8.3:report (report) on project test-rest-service: An error has occurred in JaCoCo report generation. Error while creating report: malformed input around byte 2 -> [Help 1]
Run Code Online (Sandbox Code Playgroud)

所有测试都通过而没有失败,所以这不是问题。

JaCoCo 的依赖项是:

   <plugin>
            <groupId>org.jacoco</groupId>
            <artifactId>jacoco-maven-plugin</artifactId>
            <version>0.8.3</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>
Run Code Online (Sandbox Code Playgroud)

生成了 JaCoCo.exec 文件,但我无法打开它来生成报告。我究竟做错了什么?

java maven jacoco jacoco-maven-plugin

11
推荐指数
2
解决办法
6824
查看次数

Java Spring Boot 不记录异常

我有弹簧靴休息服务。当我向服务发送请求时,我想记录它是否是成功的请求。如果rest服务成功,logger.info(任何记录器都会被记录,即使是logger.error)将被记录到控制台。但是,当抛出 SQL 异常时,它不会将 logger.error 部分记录到控制台。我如何获得它,以便如果抛出异常,它也会将该部分记录到控制台?

下面是测试方法:

import org.slf4j.Logger;
import org.slf4j.LoggerFactory   

public String testMethod(){
    try{

        LOGGER.info("running test method");

        Class.forName("oracle.jdbc.driver.OracleDriver");

        Connection test = DriverManager.getConnection(
                datasourceUrl,datasourceUsername,datasourcePassword);
        //Select data
        Statement stmt = test.createStatement();

        InputStream input = getClass().getResourceAsStream("/testMethodSQL.sql");
        String insertTableSQL = IOUtils.toString(input);

         PreparedStatement preparedStatement = prod.prepareStatement(insertTableSQL);

        ResultSet rs = preparedStatement.executeQuery();

        }

        test.close();

        LOGGER.info("test Method successfully ran");

        return "Done";
    }
    catch (Exception e) {
        e.printStackTrace();
        LOGGER.error("Error found: {}", e);
        return "An error occured: " +  e;
    }

}
Run Code Online (Sandbox Code Playgroud)

这是我的 logback.xml 文件:

<configuration>
<appender name="Console" class="ch.qos.logback.core.ConsoleAppender">
    <encoder …
Run Code Online (Sandbox Code Playgroud)

java logging spring-boot

4
推荐指数
1
解决办法
9909
查看次数

标签 统计

java ×2

jacoco ×1

jacoco-maven-plugin ×1

logging ×1

maven ×1

spring-boot ×1