Search in sources :

Example 1 with SKIPPED_TESTS

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

the class TestExecutionPublisher method updateTestExecutionFromTestPlan.

private void updateTestExecutionFromTestPlan(final InputFile inputFile, ScannerReportWriter writer) {
    final DefaultTestPlan testPlan = testPlanBuilder.getTestPlanByFile(inputFile);
    if (testPlan == null || !testPlan.testCases().iterator().hasNext()) {
        return;
    }
    long nonSkippedTests = StreamSupport.stream(testPlan.testCases().spliterator(), false).filter(t -> t.status() != Status.SKIPPED).count();
    appendMeasure(inputFile, writer, new DefaultMeasure<Integer>().forMetric(TESTS).withValue((int) nonSkippedTests));
    long executionTime = StreamSupport.stream(testPlan.testCases().spliterator(), false).map(DefaultTestCase::durationInMs).filter(Objects::nonNull).mapToLong(Long::longValue).sum();
    appendMeasure(inputFile, writer, new DefaultMeasure<Long>().forMetric(TEST_EXECUTION_TIME).withValue(executionTime));
    long errorTests = StreamSupport.stream(testPlan.testCases().spliterator(), false).filter(t -> t.status() == Status.ERROR).count();
    appendMeasure(inputFile, writer, new DefaultMeasure<Integer>().forMetric(TEST_ERRORS).withValue((int) errorTests));
    long skippedTests = StreamSupport.stream(testPlan.testCases().spliterator(), false).filter(t -> t.status() == Status.SKIPPED).count();
    appendMeasure(inputFile, writer, new DefaultMeasure<Integer>().forMetric(SKIPPED_TESTS).withValue((int) skippedTests));
    long failedTests = StreamSupport.stream(testPlan.testCases().spliterator(), false).filter(t -> t.status() == Status.FAILURE).count();
    appendMeasure(inputFile, writer, 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) InputComponentStore(org.sonar.scanner.scan.filesystem.InputComponentStore) InputComponent(org.sonar.api.batch.fs.InputComponent) TEST_EXECUTION_TIME(org.sonar.api.measures.CoreMetrics.TEST_EXECUTION_TIME) Status(org.sonar.scanner.deprecated.test.DefaultTestCase.Status) TestPlanBuilder(org.sonar.scanner.deprecated.test.TestPlanBuilder) DefaultTestPlan(org.sonar.scanner.deprecated.test.DefaultTestPlan) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) ScannerReportWriter(org.sonar.scanner.protocol.output.ScannerReportWriter) SKIPPED_TESTS(org.sonar.api.measures.CoreMetrics.SKIPPED_TESTS) TEST_ERRORS(org.sonar.api.measures.CoreMetrics.TEST_ERRORS) TESTS(org.sonar.api.measures.CoreMetrics.TESTS) DefaultSensorStorage.toReportMeasure(org.sonar.scanner.sensor.DefaultSensorStorage.toReportMeasure) Objects(java.util.Objects) DefaultTestCase(org.sonar.scanner.deprecated.test.DefaultTestCase) TEST_FAILURES(org.sonar.api.measures.CoreMetrics.TEST_FAILURES) StreamSupport(java.util.stream.StreamSupport) DefaultMeasure(org.sonar.api.batch.sensor.measure.internal.DefaultMeasure) DefaultTestPlan(org.sonar.scanner.deprecated.test.DefaultTestPlan) Objects(java.util.Objects)

Example 2 with SKIPPED_TESTS

use of org.sonar.api.measures.CoreMetrics.SKIPPED_TESTS 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

StreamSupport (java.util.stream.StreamSupport)2 InputComponent (org.sonar.api.batch.fs.InputComponent)2 InputFile (org.sonar.api.batch.fs.InputFile)2 DefaultInputComponent (org.sonar.api.batch.fs.internal.DefaultInputComponent)2 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)2 DefaultMeasure (org.sonar.api.batch.sensor.measure.internal.DefaultMeasure)2 SKIPPED_TESTS (org.sonar.api.measures.CoreMetrics.SKIPPED_TESTS)2 TESTS (org.sonar.api.measures.CoreMetrics.TESTS)2 TEST_ERRORS (org.sonar.api.measures.CoreMetrics.TEST_ERRORS)2 TEST_EXECUTION_TIME (org.sonar.api.measures.CoreMetrics.TEST_EXECUTION_TIME)2 TEST_FAILURES (org.sonar.api.measures.CoreMetrics.TEST_FAILURES)2 TestPlanBuilder (org.sonar.scanner.deprecated.test.TestPlanBuilder)2 Iterables (com.google.common.collect.Iterables)1 Serializable (java.io.Serializable)1 Collections (java.util.Collections)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Collectors (java.util.stream.Collectors)1 Type (org.sonar.api.batch.fs.InputFile.Type)1 Metric (org.sonar.api.batch.measure.Metric)1