SonarQube:使用Gradle覆盖时显示测试源

时间:2018-11-16 09:02:00

标签: jenkins gradle sonarqube code-coverage jacoco

设置

每次Jenkins管道运行Java代码库时,它都会执行Gradle任务,该任务将JaCoCo生成的代码覆盖率添加到SonarQube实例中。

sonar.gradle

void insert_at_position(struct node **head, int x, int pos)
{
  struct node *temp = *head,*t,*tails = *head;  //temp was not initialized in original code so temp->next will not point to next node.
  int i = 0; // i was not initialized in original code
  t=(struct node*)malloc(sizeof(struct node));
  if(t == NULL) // malloc fail case check
  {
      return;
  }
  if (pos == 0) // 0th position insertion handling section
  {
      t->data = x;
      t->next = start;
      start = t;
      return;
  }
  if(start == NULL) // It is better to not inset any node if  position != 0 and Start == NULL
  {
      free(t);  // If the node is not inserted free the allocated memory.
      return;
  }
  count++;    // Assuming count is an global variable
  while(temp != NULL)
  {
      tails = temp;    
      temp = temp->next;
      if(i+1 == pos) // In this case tails points to the previous location
      {
          tails->next=t;
          t->data=x;
          t->next=temp; // temp now points to the node that was originally at 'pos' position
          return;
      }
      i++;          
  }
  free(t);  // If the node is not inserted free the allocated memory.
}

gradle.properties

apply plugin: "org.sonarqube" apply plugin: 'jacoco' jacoco { toolVersion = '0.8.1' } jacocoTestReport { reports { xml.enabled true } }

问题

只要覆盖代码,SonarQube就会在覆盖行的开头显示一个绿色标记。单击此绿色标记时,我得到:
enter image description here
我希望这个弹出窗口显示哪个测试覆盖了这一行。我假设这是可能的,因为这篇文章(Sonarqube: view unit tests that cover the source)描述了如何使用Maven来完成。

我可以使用Gradle做到吗?

0 个答案:

没有答案