【发布时间】:2021-02-22 03:47:44
【问题描述】:
我已经模拟了 Spring Boot 服务类来测试 catch 块语句。我的示例测试用例如下:
@SpyBean
private EmployeeService employeeService;
@Test
public void employeedetails() throws CustomException {
Employee employee= new Employee();
Mockito.when(employeeService .getEmployeeDetails(employee))
.thenThrow(new CustomException("Exception while getting the employee details"));
CustomException exception = Assertions.assertThrows(
CustomException.class,
() -> employeeService.getEmployeeDetails(caution));
}
POM:
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<executions>
<execution>
<id>aggregate-coverage-reports</id>
<phase>test</phase>
<goals>
<goal>report-aggregate</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
测试用例执行良好,但未反映在 Java 代码覆盖率报告中。我的 catch 语句仍然显示它没有被测试覆盖。
可能是什么原因?
参考
【问题讨论】:
标签: java code-coverage junit5 jacoco