Search in sources :

Example 1 with TEST_FAILURES

use of org.sonar.api.measures.CoreMetrics.TEST_FAILURES in project sonarqube by SonarSource.

the class MeasuresPublisher method updateTestExecutionFromTestPlan.

private void updateTestExecutionFromTestPlan(final InputFile inputFile) {
    final MutableTestPlan testPlan = testPlanBuilder.getTestPlanByFile(inputFile);
    if (testPlan == null || Iterables.isEmpty(testPlan.testCases())) {
        return;
    }
    long nonSkippedTests = StreamSupport.stream(testPlan.testCases().spliterator(), false).filter(t -> t.status() != Status.SKIPPED).count();
    measureCache.put(inputFile.key(), TESTS_KEY, new DefaultMeasure<Integer>().forMetric(TESTS).withValue((int) nonSkippedTests));
    long executionTime = StreamSupport.stream(testPlan.testCases().spliterator(), false).mapToLong(t -> t.durationInMs() != null ? t.durationInMs().longValue() : 0L).sum();
    measureCache.put(inputFile.key(), TEST_EXECUTION_TIME_KEY, new DefaultMeasure<Long>().forMetric(TEST_EXECUTION_TIME).withValue(executionTime));
    long errorTests = StreamSupport.stream(testPlan.testCases().spliterator(), false).filter(t -> t.status() == Status.ERROR).count();
    measureCache.put(inputFile.key(), TEST_ERRORS_KEY, new DefaultMeasure<Integer>().forMetric(TEST_ERRORS).withValue((int) errorTests));
    long skippedTests = StreamSupport.stream(testPlan.testCases().spliterator(), false).filter(t -> t.status() == Status.SKIPPED).count();
    measureCache.put(inputFile.key(), SKIPPED_TESTS_KEY, new DefaultMeasure<Integer>().forMetric(SKIPPED_TESTS).withValue((int) skippedTests));
    long failedTests = StreamSupport.stream(testPlan.testCases().spliterator(), false).filter(t -> t.status() == Status.FAILURE).count();
    measureCache.put(inputFile.key(), TEST_FAILURES_KEY, new DefaultMeasure<Integer>().forMetric(TEST_FAILURES).withValue((int) failedTests));
}
Also used : DefaultInputComponent(org.sonar.api.batch.fs.internal.DefaultInputComponent) InputFile(org.sonar.api.batch.fs.InputFile) Metric(org.sonar.api.batch.measure.Metric) Iterables(com.google.common.collect.Iterables) InputComponentStore(org.sonar.scanner.scan.filesystem.InputComponentStore) SKIPPED_TESTS_KEY(org.sonar.api.measures.CoreMetrics.SKIPPED_TESTS_KEY) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) ScannerReportWriter(org.sonar.scanner.protocol.output.ScannerReportWriter) SKIPPED_TESTS(org.sonar.api.measures.CoreMetrics.SKIPPED_TESTS) LINES_TO_COVER(org.sonar.api.measures.CoreMetrics.LINES_TO_COVER) Type(org.sonar.api.batch.fs.InputFile.Type) TESTS(org.sonar.api.measures.CoreMetrics.TESTS) ScannerReport(org.sonar.scanner.protocol.output.ScannerReport) UNCOVERED_LINES_KEY(org.sonar.api.measures.CoreMetrics.UNCOVERED_LINES_KEY) TEST_ERRORS_KEY(org.sonar.api.measures.CoreMetrics.TEST_ERRORS_KEY) CONDITIONS_TO_COVER_KEY(org.sonar.api.measures.CoreMetrics.CONDITIONS_TO_COVER_KEY) TEST_FAILURES_KEY(org.sonar.api.measures.CoreMetrics.TEST_FAILURES_KEY) UNCOVERED_CONDITIONS(org.sonar.api.measures.CoreMetrics.UNCOVERED_CONDITIONS) Status(org.sonar.api.test.TestCase.Status) CONDITIONS_TO_COVER(org.sonar.api.measures.CoreMetrics.CONDITIONS_TO_COVER) StringValue(org.sonar.scanner.protocol.output.ScannerReport.Measure.StringValue) Map(java.util.Map) TEST_EXECUTION_TIME_KEY(org.sonar.api.measures.CoreMetrics.TEST_EXECUTION_TIME_KEY) StreamSupport(java.util.stream.StreamSupport) UNCOVERED_CONDITIONS_KEY(org.sonar.api.measures.CoreMetrics.UNCOVERED_CONDITIONS_KEY) LINES_TO_COVER_KEY(org.sonar.api.measures.CoreMetrics.LINES_TO_COVER_KEY) InputComponent(org.sonar.api.batch.fs.InputComponent) TEST_EXECUTION_TIME(org.sonar.api.measures.CoreMetrics.TEST_EXECUTION_TIME) TestPlanBuilder(org.sonar.scanner.deprecated.test.TestPlanBuilder) IntValue(org.sonar.scanner.protocol.output.ScannerReport.Measure.IntValue) LongValue(org.sonar.scanner.protocol.output.ScannerReport.Measure.LongValue) TEST_ERRORS(org.sonar.api.measures.CoreMetrics.TEST_ERRORS) MeasureCache(org.sonar.scanner.scan.measure.MeasureCache) Collectors(java.util.stream.Collectors) CoreMetrics(org.sonar.api.measures.CoreMetrics) Serializable(java.io.Serializable) MutableTestPlan(org.sonar.api.test.MutableTestPlan) BoolValue(org.sonar.scanner.protocol.output.ScannerReport.Measure.BoolValue) TEST_FAILURES(org.sonar.api.measures.CoreMetrics.TEST_FAILURES) TESTS_KEY(org.sonar.api.measures.CoreMetrics.TESTS_KEY) UNCOVERED_LINES(org.sonar.api.measures.CoreMetrics.UNCOVERED_LINES) DefaultMeasure(org.sonar.api.batch.sensor.measure.internal.DefaultMeasure) KeyValueFormat(org.sonar.api.utils.KeyValueFormat) Collections(java.util.Collections) DoubleValue(org.sonar.scanner.protocol.output.ScannerReport.Measure.DoubleValue) MutableTestPlan(org.sonar.api.test.MutableTestPlan)

Aggregations

Iterables (com.google.common.collect.Iterables)1 Serializable (java.io.Serializable)1 Collections (java.util.Collections)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 StreamSupport (java.util.stream.StreamSupport)1 InputComponent (org.sonar.api.batch.fs.InputComponent)1 InputFile (org.sonar.api.batch.fs.InputFile)1 Type (org.sonar.api.batch.fs.InputFile.Type)1 DefaultInputComponent (org.sonar.api.batch.fs.internal.DefaultInputComponent)1 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)1 Metric (org.sonar.api.batch.measure.Metric)1 DefaultMeasure (org.sonar.api.batch.sensor.measure.internal.DefaultMeasure)1 CoreMetrics (org.sonar.api.measures.CoreMetrics)1 CONDITIONS_TO_COVER (org.sonar.api.measures.CoreMetrics.CONDITIONS_TO_COVER)1 CONDITIONS_TO_COVER_KEY (org.sonar.api.measures.CoreMetrics.CONDITIONS_TO_COVER_KEY)1 LINES_TO_COVER (org.sonar.api.measures.CoreMetrics.LINES_TO_COVER)1 LINES_TO_COVER_KEY (org.sonar.api.measures.CoreMetrics.LINES_TO_COVER_KEY)1 SKIPPED_TESTS (org.sonar.api.measures.CoreMetrics.SKIPPED_TESTS)1 SKIPPED_TESTS_KEY (org.sonar.api.measures.CoreMetrics.SKIPPED_TESTS_KEY)1