简体   繁体   English

Jacoco 报告显示已删除的 Java 类以进行测试覆盖

[英]Jacoco report showing deleted java class for test coverage

I have simply deleted the java class file which was of no use.After building the package in intellij, Jacoco test report showing deleted java class as well.我只是删除了没有用的java类文件。在intellij中构建包后,Jacoco测试报告也显示了已删除的java类。 For reference, I have attached sceenshot.作为参考,我附上了 sceenshot。

Is there any reference exists even after deleting java class file in intellij.即使在intellij中删除java类文件后,是否存在任何引用? How can I completely resolve this issue?我怎样才能彻底解决这个问题? 在此处输入图片说明

Run the clean command for whatever build tool you are using (ant, maven, gradle).为您使用的任何构建工具(ant、maven、gradle)运行clean命令。

If you only run the jacocoTestReport occasionally, you might want to add a dependency on clean for it, to ensure it always happens before generating the report.如果您只是偶尔运行jacocoTestReport ,您可能需要为其添加对clean的依赖,以确保它始终在生成报告之前发生。

I noticed this same problem when I changed a package name on a class and the old package was still in the report.当我更改类上的包名称并且旧包仍在报告中时,我注意到了同样的问题。

What is happening is the report that is created is simply a bunch of files that follow the naming and package convention of the files in your project.发生的事情是创建的报告只是一堆文件,这些文件遵循项目中文件的命名和包约定。 So files from a previous run of jacocoTestReport are still sitting in that report folder, even though you have deleted the java file, and rerun jacocoTestReport .因此,即使您已删除 java 文件并重新运行jacocoTestReport ,先前运行jacocoTestReport文件仍位于该报告文件夹中。 If you look in the folder, you will find the timestamp is older on the report file for the deleted class than the others around it.如果您查看文件夹,您会发现已删除类的报告文件中的时间戳比周围的其他文件要旧。 It just needs the clean so that your next run will only contain files related to the current report.它只需要clean以便您的下一次运行将只包含与当前报告相关的文件。

I assume its possible to change where jacocoTestReport will write its report files and if you choose somewhere other than the build directory, you would need to update your clean task to clean up that area too.我认为可以更改jacocoTestReport将在哪里写入报告文件,如果您选择构建目录以外的其他位置,则还需要更新您的clean任务以清理该区域。

The same thing happened to me today.今天同样的事情发生在我身上。 It was due to:这是由于:

  • checking out to a git branch in which a maven module has been deleted签出到已删除 Maven 模块的 git 分支
  • the corresponding folder was still here, but it was ignored by git since it only contained ignored files (eg .class files inside target/ )相应的文件夹仍然在这里,但它被 git 忽略了,因为它只包含被忽略的文件(例如target/ .class文件)
  • mvn clean did not clean those files, since the corresponding module was removed from pom.xml mvn clean没有清理这些文件,因为相应的模块已从pom.xml中删除
  • Jacoco still found the old compiled classes because it looks for **/classes and **/**.exec , and it doesn't care about .gitignore or pom.xml . Jacoco 仍然找到旧的编译类,因为它查找**/classes**/**.exec ,并且它不关心.gitignorepom.xml

After removing remove the old files, the coverage reported by Jacoco changed.删除删除旧文件后,Jacoco 报告的覆盖率发生了变化。

I used git clean -f -d --dry-run to look for old folders, and removed them with git clean -f -d .我使用git clean -f -d --dry-run来查找旧文件夹,并使用git clean -f -d删除它们。 Please be careful with this command!请小心使用此命令!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM