use of org.sonar.scanner.deprecated.test.DefaultTestCase 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.DefaultTestCase in project sonarqube by SonarSource.
the class GenericTestExecutionReportParser method parseTestCase.
private static void parseTestCase(SMInputCursor cursor, DefaultTestPlan testPlan) throws XMLStreamException {
checkElementName(cursor, "testCase");
DefaultTestCase testCase = testPlan.addTestCase(mandatoryAttribute(cursor, NAME_ATTR));
Status status = Status.OK;
testCase.setDurationInMs(longValue(mandatoryAttribute(cursor, DURATION_ATTR), cursor, DURATION_ATTR, 0));
SMInputCursor child = cursor.descendantElementCursor();
if (child.getNext() != null) {
String elementName = child.getLocalName();
if (SKIPPED.equals(elementName)) {
status = Status.SKIPPED;
} else if (FAILURE.equals(elementName)) {
status = Status.FAILURE;
} else if (ERROR.equals(elementName)) {
status = Status.ERROR;
}
if (Status.OK != status) {
testCase.setMessage(mandatoryAttribute(child, MESSAGE_ATTR));
}
}
testCase.setStatus(status);
}
use of org.sonar.scanner.deprecated.test.DefaultTestCase in project sonarqube by SonarSource.
the class GenericTestExecutionReportParserTest method mockMutableTestCase.
private DefaultTestCase mockMutableTestCase() {
DefaultTestCase testCase = mock(DefaultTestCase.class);
when(testCase.setDurationInMs(anyLong())).thenReturn(testCase);
when(testCase.setStatus(any(DefaultTestCase.Status.class))).thenReturn(testCase);
when(testCase.setMessage(anyString())).thenReturn(testCase);
when(testCase.setType(anyString())).thenReturn(testCase);
return testCase;
}
use of org.sonar.scanner.deprecated.test.DefaultTestCase in project sonarqube by SonarSource.
the class GenericTestExecutionReportParserTest method before.
@Before
public void before() {
context = SensorContextTester.create(new File(""));
fileWithBranches = setupFile("src/main/java/com/example/ClassWithBranches.java");
emptyFile = setupFile("src/main/java/com/example/EmptyClass.java");
testPlanBuilder = mock(TestPlanBuilder.class);
DefaultTestCase testCase = mockMutableTestCase();
testPlan = mockMutableTestPlan(testCase);
when(testPlanBuilder.getTestPlan(any(InputFile.class))).thenReturn(testPlan);
}
Aggregations