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));
}
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);
}
}
}
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;
}
Aggregations