Arts Arts
Arts Arts

Reputation: 9

JaCoCo ant code coverage

How do you fix this??

For the following line in my program JaCoCo shows: "1 of 2 branches missed"

if(ia.length() < i+1){

Also for the following line i get: "1 of 4 branches missed"

if(ia.length() <= i+1 && ib.length() <= i+1){

the whole code:

public static int convertBits(int a, int b) {
      String ia = Integer.toBinaryString(a);
      String ib = Integer.toBinaryString(b);
      int s = 0;
      for(int i = 0;;i++){
        char a1 = '0';
        char a2 = '0';

        if(ia.length() < i+1){
          a1 = '0';
        }else{
          a1 = ia.charAt(ia.length() - i - 1);
          }
        if(ib.length() < i+1){
          a2 = '0';
        }else{
          a2 = ib.charAt(ib.length() - i - 1);
          }
        if(a1 != a2){
          s++;
        }
        if(ia.length() <= i+1 && ib.length() <= i+1){
          break;
        }
      }

Upvotes: 0

Views: 126

Answers (1)

Godin
Godin

Reputation: 10564

JaCoCo is a code coverage tool that generates coverage report of your code after its execution. Could be after manual execution, but typically after execution of tests, thus doing assistance in their creation.

Condition if (ia.length() < i + 1) { has two branches:

  1. ia.length() < i + 1 == false
  2. ia.length() < i + 1 == true

So

1 out of 2 branches

means that one of those branches was executed, while another was not.

Upvotes: 2

Related Questions