本文介绍了IntelliJ显示更改了单元测试未涵盖的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的日常工作中,我打算为我更改的代码编写测试。

In my daily work, I intend to write tests for the code that I change.

我的工作流程通常是这样的:

My workflow usually is like this:


  • 查找要更改的代码

  • 写入失败的测试

  • 更改代码

  • 观看测试通行证

  • Find code to change
  • Write failing test
  • Change code
  • Watch test pass

在提交之前,我运行所有测试。

And before commit, I run all tests.

但实际上,我可以在不知不觉中改变任何关于我们测试覆盖率的行。

But in reality, I could change any lines unknowingly about our test coverage.

我现在做的通常是查看CI服务器是否会显示增加测试覆盖率。但这是我在提交后必须完成的手动任务,也可能被其他人提交代码混乱。

What I do now is usually to see if the CI server will show increasing test coverage. But this is a manual task which I have to do after my commit, and it also may be cluttered by others committing code.

IntelliJ如何帮助我?我无法直接找到比较测试覆盖率的方法。如何确保我的更改推动测试覆盖率?

How can IntelliJ help me? I cannot directly find a way to compare test coverage. How can I ensure my changes drive test coverage up?

您目前如何处理代码覆盖的这一方面?

How do you currently handle this aspect of your code coverage?

推荐答案

IntelliJ IDEA包括支持自6.0版本(终极版)。

IntelliJ IDEA includes the code coverage support since the 6.0 version (Ultimate edition).

通过运行 - >编辑配置 - >代码覆盖率您可以配置所需的代码覆盖率,然后您可以发出使用coverage命令运行测试。因此,您将在项目视图中获得一些代码覆盖率数据。当您打开源文件时,您还可以看到完全覆盖,部分覆盖或未覆盖哪些行。

Through Run -> Edit Configurations -> Code Coverage you can configure the code coverage you want, then you can issue the "Run tests with coverage" command. You'll have as a result some code coverage data on the project view. When you open a source file you can also see what lines are fully covered, partially covered, or not covered at all.

您可能想要自定义颜色和放大。字体通过文件 - >设置 - >编辑器 - >颜色和&字体 - >一般修改以下条目:

You might want to customize the Colors & Fonts through File -> Settings -> Editor -> Colors & Fonts -> General modifying the following entries:


  • 全线覆盖

  • 部分线路覆盖

  • 未覆盖的行

例如,我想为覆盖范围添加更多的证据,所以我配置了这些线的不同背景。

For example I wanted to add more evidency to the coverage, so I configured a different background for those lines.

一旦你有一些红线(没有覆盖),你可以尝试覆盖它们,如果你看到它们变绿,这意味着你做了一个干得好,等等!

Once you have some red lines (not covered), you can try to cover them and if you see them becoming green it means you did a good job, and so on!

这篇关于IntelliJ显示更改了单元测试未涵盖的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 06:36