Java 使用 IntelliJ 的 JaCoCo
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/43500774/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
JaCoCo with IntelliJ
提问by Ixbitz
So this question might not be really specific, but i'm asking it anyway.
所以这个问题可能不是很具体,但我还是问了。
I'm trying to use JaCoCo with IntelliJ to gather coverage reports on unit tests. However, i don't have any experience whatsoever to set this up.
我正在尝试将 JaCoCo 与 IntelliJ 一起使用来收集有关单元测试的覆盖率报告。但是,我没有任何经验来设置它。
In Netbeans you just have to install the JaCoCo plugin and select to test with coverage. How does this work in IntelliJ?
在 Netbeans 中,您只需安装 JaCoCo 插件并选择使用覆盖率进行测试。这在 IntelliJ 中是如何工作的?
I have googeled for quite a while without success. If someone has a good tutorial to set this up, i'd really appreciate it!
我已经谷歌搜索了很长一段时间没有成功。如果有人有一个很好的教程来设置它,我真的很感激!
回答by Crt
Have you looked at this document : https://www.jetbrains.com/help/idea/2017.1/code-coverage.html
你看过这个文件:https: //www.jetbrains.com/help/idea/2017.1/code-coverage.html
They describe how to do such a task.
他们描述了如何完成这样的任务。
回答by jwenting
You don't need to do anything, if you have a recent version of IntelliJ. Just select to use JaCoCo as the coverage tool in the run configuration for your test suite or project and it will use its built-in JaCoCo version.
如果您有最新版本的 IntelliJ,则无需执行任何操作。只需选择在测试套件或项目的运行配置中使用 JaCoCo 作为覆盖工具,它将使用其内置的 JaCoCo 版本。
回答by firstpostcommenter
Intellij shows code coverage in the IDE. There is no need to install any extra plugins
Intellij 在 IDE 中显示代码覆盖率。无需安装任何额外的插件
when you right click on a Test.java file to run the unit test then there will be 3 options
当您右键单击 Test.java 文件以运行单元测试时,将有 3 个选项
Run "Test"
Debug "Test"
Run "Test" with **coverage**
Secondly, if you also want the branch coverage details then,
其次,如果您还想要分支机构覆盖范围的详细信息,
after running the test(as mentioned above) once, then then go to edit configuration -> at left side under Junit select the respective Test.java file -> select Code Coverage tab in the main window -> select Tracing radio button and tick the Track per test coverage checkbox
运行测试(如上所述)一次后,然后转到 edit configuration -> at left side under Junit select the respective Test.java file -> select Code Coverage tab in the main window -> select Tracing radio button and tick the Track per test coverage checkbox
回答by Stevers
You have to open your Run Configuration
1A. (top right by default)
Tests in <project package>
1B. If you can't find it, you can go to the
Run
menu at the top, then click theRun > ...
option. This will show you your configurations.click
Edit Configurations
. Find yourTests in <project package>
configuration.Find Second tab from the left is
Code Coverage
. Choose Coverage Runner:Jacoco
.Apply
.OK
.Run tests again :).
你必须打开你的运行配置
1A。(默认右上角)
Tests in <project package>
1B。如果找不到,可以转到
Run
顶部的菜单,然后单击该Run > ...
选项。这将显示您的配置。单击
Edit Configurations
。找到您的Tests in <project package>
配置。查找左侧的第二个选项卡是
Code Coverage
。选择 Coverage Runner:Jacoco
。Apply
.OK
.再次运行测试:)。
回答by bigT
To elaborate on jwenting's answer, go to Run> Edit Configurations..., and on the Code Coveragetab of your Run Configuration, select JaCoCofrom the Choose coverage runnerdropdown.
要详细说明jwenting的答案,请转到Run> Edit Configurations...,然后在Run Configuration的Code Coverage选项卡上,从Choose coverage runner下拉列表中选择JaCoCo。