开发者

IntelliJ show changed lines not covered by unit tests

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.

What I do now is usually to see if the CI server will show increasing test coverage. But this is a manua开发者_如何学Pythonl task which I have to do after my commit, and it also may be cluttered by others committing code.

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 includes the code coverage support since the 6.0 version (Ultimate edition).

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:

  • Full line coverage
  • Partial line coverage
  • Uncovered line

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!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜