Search in sources :

Example 1 with DefaultTestPlan

use of org.sonar.scanner.deprecated.test.DefaultTestPlan 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 DefaultTestPlan

use of org.sonar.scanner.deprecated.test.DefaultTestPlan in project sonarqube by SonarSource.

the class GenericTestExecutionReportParser method parseFiles.

private void parseFiles(SMInputCursor fileCursor, SensorContext context) throws XMLStreamException {
    while (fileCursor.getNext() != null) {
        checkElementName(fileCursor, "file");
        String filePath = mandatoryAttribute(fileCursor, "path");
        InputFile inputFile = context.fileSystem().inputFile(context.fileSystem().predicates().hasPath(filePath));
        if (inputFile == null || inputFile.language() == null) {
            numberOfUnknownFiles++;
            if (numberOfUnknownFiles <= MAX_STORED_UNKNOWN_FILE_PATHS) {
                firstUnknownFiles.add(filePath);
            }
            if (inputFile != null) {
                LOG.debug("Skipping file '{}' in the generic test execution report because it doesn't have a known language", filePath);
            }
            continue;
        }
        checkState(inputFile.type() != InputFile.Type.MAIN, "Line %s of report refers to a file which is not configured as a test file: %s", fileCursor.getCursorLocation().getLineNumber(), filePath);
        matchedFileKeys.add(inputFile.absolutePath());
        DefaultTestPlan testPlan = testPlanBuilder.getTestPlan(inputFile);
        SMInputCursor testCaseCursor = fileCursor.childElementCursor();
        while (testCaseCursor.getNext() != null) {
            parseTestCase(testCaseCursor, testPlan);
        }
    }
}
Also used : SMInputCursor(org.codehaus.staxmate.in.SMInputCursor) DefaultTestPlan(org.sonar.scanner.deprecated.test.DefaultTestPlan) InputFile(org.sonar.api.batch.fs.InputFile)

Example 3 with DefaultTestPlan

use of org.sonar.scanner.deprecated.test.DefaultTestPlan in project sonarqube by SonarSource.

the class GenericTestExecutionReportParserTest method mockMutableTestPlan.

private DefaultTestPlan mockMutableTestPlan(DefaultTestCase testCase) {
    DefaultTestPlan testPlan = mock(DefaultTestPlan.class);
    when(testPlan.addTestCase(anyString())).thenReturn(testCase);
    return testPlan;
}
Also used : DefaultTestPlan(org.sonar.scanner.deprecated.test.DefaultTestPlan)

Aggregations

DefaultTestPlan (org.sonar.scanner.deprecated.test.DefaultTestPlan)3 InputFile (org.sonar.api.batch.fs.InputFile)2 Objects (java.util.Objects)1 StreamSupport (java.util.stream.StreamSupport)1 SMInputCursor (org.codehaus.staxmate.in.SMInputCursor)1 InputComponent (org.sonar.api.batch.fs.InputComponent)1 DefaultInputComponent (org.sonar.api.batch.fs.internal.DefaultInputComponent)1 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)1 DefaultMeasure (org.sonar.api.batch.sensor.measure.internal.DefaultMeasure)1 SKIPPED_TESTS (org.sonar.api.measures.CoreMetrics.SKIPPED_TESTS)1 TESTS (org.sonar.api.measures.CoreMetrics.TESTS)1 TEST_ERRORS (org.sonar.api.measures.CoreMetrics.TEST_ERRORS)1 TEST_EXECUTION_TIME (org.sonar.api.measures.CoreMetrics.TEST_EXECUTION_TIME)1 TEST_FAILURES (org.sonar.api.measures.CoreMetrics.TEST_FAILURES)1 DefaultTestCase (org.sonar.scanner.deprecated.test.DefaultTestCase)1 Status (org.sonar.scanner.deprecated.test.DefaultTestCase.Status)1 TestPlanBuilder (org.sonar.scanner.deprecated.test.TestPlanBuilder)1 ScannerReportWriter (org.sonar.scanner.protocol.output.ScannerReportWriter)1 InputComponentStore (org.sonar.scanner.scan.filesystem.InputComponentStore)1 DefaultSensorStorage.toReportMeasure (org.sonar.scanner.sensor.DefaultSensorStorage.toReportMeasure)1