IntelliJ Setup Branch Code Coverage

When we write code we usually make a lot of logical conditions in our if/switch cases. When we execute our tests the default settings on IntelliJ do not make branch coverage. That is essential to be sure that you tested all of the code logix paths in tour valuable product.

Here we will show you in detailed steps how to enable the branch code coverage.

Switch on by default for the JUnit Template

We will first edit the JUnit template so all our future tests executions to have the settings switched on by default.

Switch on for existing JUnit Configurations

Existing JUnit settings will be with the old configuration so you should switch them on manually. 

The settings is in the same place but when you edit your existing JUnit configurations:

Branch Code Coverage Data

After executing with the new branch option you will see one new column Branch % in the code coverage stats.

Also in the code you will see yellow indications where the boolean condition branch was not covered with all its cases like the example below:


Summary

With this tool in hand you could easily verify that your tests cover all your valuable business cases where you implement as different code branches.

Share

Share on facebook
Share on google
Share on twitter
Share on linkedin
Share on pinterest
Share on print
Share on email