IntelliJ show changed lines not covered by unit tests

后端 未结 1 1590
梦谈多话
梦谈多话 2021-02-06 05:17

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
1条回答
  •  [愿得一人]
    2021-02-06 05:43

    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 讨论(0)
提交回复
热议问题