Unable to fetch Integration Tests results from Sonar WS API

35 views
Skip to first unread message

inbox.ma...@gmail.com

unread,
Apr 14, 2016, 5:52:02 PM4/14/16
to SonarQube
Hi All,

I'm preparing a customized report of metrices present on SonarQube Dashboard, predominantly, Unit Test & Integration Test execution & coverage matrix. I succeed in getting it for Unit Tests but it seems there are no matrics keys available to fetch Integration & overall coverage statistics. I'm using SonarQube 4.5.6. Please also guide me if there is another way to export the Sonar Dashboard Stats as HTML. The code is as follows:

public class TestStatistics{
static String host = "http://my.server.com/Sonar";
static String login = "admin";
static String password = "admin";
   static String resourceKey = "shift:shift";
   static String[] MEASURES_TO_GET =  new String[]{"branch_coverage",
    "new_branch_coverage",
    "branch_coverage_hits_data",
    "conditions_by_line",
    "covered_conditions_by_line",
    "coverage",
    "new_coverage",
    "line_coverage",
    "new_line_coverage",
    "coverage_line_hits_data",
    "lines_to_cover",
    "new_lines_to_cover",
    "skipped_tests",
    "uncovered_conditions",
    "new_uncovered_conditions",
    "uncovered_lines",
    "new_uncovered_lines",
    "tests",
    "test_execution_time",
    "test_errors",
    "test_failures",
    "test_success_density"
    };
 
   public static void main(String[] args) {                
       try {       
           Date date = new Date();
 
           Sonar sonar = new Sonar(new HttpClient4Connector(new Host(host, login, password)));
           ResourceQuery query = ResourceQuery.createForMetrics(resourceKey, MEASURES_TO_GET);
           query.setIncludeTrends(true);
           List<Resource> resources = sonar.findAll(query);
           for(Resource resource:resources){
            List<Measure> allMeasures = resource.getMeasures();
            System.out.println("All Measures : "+allMeasures.toString());
            System.out.println("Unit Branch Coverage : "+resource.getMeasureValue("branch_coverage"));
            System.out.println("Unit Test Coverage : "+resource.getMeasureValue("coverage"));
            System.out.println("Unit Line Coverage : "+resource.getMeasureValue("line_coverage"));
            System.out.println("Lines To Cover : "+resource.getMeasureValue("lines_to_cover"));
            System.out.println("Skipped Tests : "+resource.getMeasureValue("skipped_tests"));
            System.out.println("Uncovered Conditions : "+resource.getMeasureValue("uncovered_conditions"));
            System.out.println("Uncovered Lines : "+resource.getMeasureValue("uncovered_lines"));
            System.out.println("Unit Tests : "+resource.getMeasureValue("tests"));
            System.out.println("Unit Test Execution Time : "+resource.getMeasureValue("test_execution_time"));
            System.out.println("Unit Tests Errors : "+resource.getMeasureValue("test_errors"));
            System.out.println("Unit Tests Failures : "+resource.getMeasureValue("test_failures"));
            System.out.println("Unit Tests Success Density : "+resource.getMeasureValue("test_success_density"));
           }
              System.out.println("DONE");
       } catch (Exception e) {
           e.printStackTrace();
       }
   }
}

Julien Lancelot

unread,
Apr 15, 2016, 3:06:57 AM4/15/16
to inbox.ma...@gmail.com, SonarQube
Hi,

Please don't cross post on Stackoverflow and here. There is limited bandwidth for community support, and you've just used twice your share for this question.


--
You received this message because you are subscribed to the Google Groups "SonarQube" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonarqube+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarqube/77f2f9c7-576a-4adc-9765-eecd96166d69%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
Julien LANCELOT | SonarSource
Reply all
Reply to author
Forward
0 new messages