use of com.google.idea.blaze.base.run.smrunner.BlazeXmlSchema.TestSuite in project intellij by bazelbuild.
the class BlazeXmlToTestEventsConverter method processTestSuite.
private static void processTestSuite(GeneralTestEventsProcessor processor, BlazeTestEventsHandler eventsHandler, @Nullable Kind kind, TestSuite suite) {
if (!hasRunChild(suite)) {
return;
}
// only include the innermost 'testsuite' element
boolean logSuite = !eventsHandler.ignoreSuite(kind, suite);
if (suite.name != null && logSuite) {
TestSuiteStarted suiteStarted = new TestSuiteStarted(eventsHandler.suiteDisplayName(kind, suite.name));
String locationUrl = eventsHandler.suiteLocationUrl(kind, suite.name);
processor.onSuiteStarted(new TestSuiteStartedEvent(suiteStarted, locationUrl));
}
for (TestSuite child : suite.testSuites) {
processTestSuite(processor, eventsHandler, kind, child);
}
for (TestSuite decorator : suite.testDecorators) {
processTestSuite(processor, eventsHandler, kind, decorator);
}
for (TestCase test : suite.testCases) {
processTestCase(processor, eventsHandler, kind, suite, test);
}
if (suite.sysOut != null) {
processor.onUncapturedOutput(suite.sysOut, ProcessOutputTypes.STDOUT);
}
if (suite.sysErr != null) {
processor.onUncapturedOutput(suite.sysErr, ProcessOutputTypes.STDERR);
}
if (suite.name != null && logSuite) {
processor.onSuiteFinished(new TestSuiteFinishedEvent(eventsHandler.suiteDisplayName(kind, suite.name)));
}
}
use of com.google.idea.blaze.base.run.smrunner.BlazeXmlSchema.TestSuite in project intellij by bazelbuild.
the class BlazeXmlSchemaTest method testNoTestSuitesOuterElement.
@Test
public void testNoTestSuitesOuterElement() {
TestSuite parsed = parseXml(" <testsuite name=\"foo/bar\" tests=\"1\" time=\"19.268\">", " <testcase name=\"TestName\" result=\"completed\" status=\"run\" time=\"19.2\">", " <system-out>PASS

</system-out>", " </testcase>", " </testsuite>");
assertThat(parsed).isNotNull();
}
use of com.google.idea.blaze.base.run.smrunner.BlazeXmlSchema.TestSuite in project intellij by bazelbuild.
the class BlazeXmlToTestEventsConverter method processTestSuites.
/**
* Process all test XML files from a single test target.
*/
private void processTestSuites(Label label, Collection<BlazeTestResult> results) {
List<File> outputFiles = new ArrayList<>();
results.forEach(result -> outputFiles.addAll(result.getOutputXmlFiles()));
if (noUsefulOutput(results, outputFiles)) {
Optional<TestStatus> status = results.stream().map(BlazeTestResult::getTestStatus).findFirst();
status.ifPresent(testStatus -> reportTargetWithoutOutputFiles(label, testStatus));
return;
}
List<TestSuite> targetSuites = new ArrayList<>();
for (File file : outputFiles) {
try (InputStream input = new FileInputStream(file)) {
targetSuites.add(BlazeXmlSchema.parse(input));
} catch (Exception e) {
// ignore parsing errors -- most common cause is user cancellation, which we can't easily
// recognize.
}
}
if (targetSuites.isEmpty()) {
return;
}
Kind kind = results.stream().map(BlazeTestResult::getTargetKind).filter(Objects::nonNull).findFirst().orElse(null);
BlazeTestEventsHandler eventsHandler = BlazeTestEventsHandler.getHandlerForTargetKindOrFallback(kind);
TestSuite suite = targetSuites.size() == 1 ? targetSuites.get(0) : BlazeXmlSchema.mergeSuites(targetSuites);
processTestSuite(getProcessor(), eventsHandler, kind, suite);
}
use of com.google.idea.blaze.base.run.smrunner.BlazeXmlSchema.TestSuite in project intellij by bazelbuild.
the class BlazeXmlSchemaTest method testTestCaseWithMultipleFailures.
@Test
public void testTestCaseWithMultipleFailures() {
TestSuite parsed = parseXml("<?xml version='1.0' encoding='UTF-8'?>", "<testsuites>", " <testsuite name='com.google.ConfigTest' time='10' tests='2' failures='1'>", " <testcase name='testCase1' time='7.9' status='run' result='completed'>", " <failure message='failed' type='AssertionError'>Error message</failure>", " <failure message='failed2' type='AssertionError'>Another Error</failure>", " </testcase>", " </testsuite>", "</testsuites>");
assertThat(parsed.testSuites.get(0).testCases).hasSize(1);
assertThat(parsed.testSuites.get(0).failures).isEqualTo(1);
TestCase testCase = parsed.testSuites.get(0).testCases.get(0);
assertThat(testCase.failures).hasSize(2);
assertThat(testCase.failures.get(0).message).isEqualTo("failed");
assertThat(testCase.failures.get(0).content).isEqualTo("Error message");
assertThat(testCase.failures.get(1).message).isEqualTo("failed2");
assertThat(testCase.failures.get(1).content).isEqualTo("Another Error");
}
use of com.google.idea.blaze.base.run.smrunner.BlazeXmlSchema.TestSuite in project intellij by bazelbuild.
the class BlazeXmlSchemaTest method testMergeShardedTests.
@Test
public void testMergeShardedTests() {
TestSuite shard1 = parseXml("<?xml version='1.0' encoding='UTF-8'?>", "<testsuites>", " <testsuite name='com.google.ConfigTest' time='10' tests='2' failures='1'>", " <testcase name='testCase1' time='2.1' status='run' result='completed'/>", " <testcase name='testCase2' time='7.9' status='run' result='completed'>", " <failure message='failed'/>", " </testcase>", " </testsuite>", "</testsuites>");
TestSuite shard2 = parseXml("<?xml version='1.0' encoding='UTF-8'?>", "<testsuites>", " <testsuite name='com.google.ConfigTest' time='5' tests='2' failures='1'>", " <testcase name='testCase3' time='1' status='run' result='completed'/>", " <testcase name='testCase4' time='4' status='run' result='completed'>", " <failure message='failed'/>", " </testcase>", " </testsuite>", "</testsuites>");
TestSuite mergedOuter = BlazeXmlSchema.mergeSuites(ImmutableList.of(shard1, shard2));
assertThat(mergedOuter.testSuites).hasSize(1);
TestSuite mergedInner = mergedOuter.testSuites.get(0).testSuites.get(0);
assertThat(mergedInner.name).isEqualTo("com.google.ConfigTest");
assertThat(mergedInner.time).isEqualTo(15d);
assertThat(mergedInner.tests).isEqualTo(4);
assertThat(mergedInner.failures).isEqualTo(2);
assertThat(mergedInner.testCases).hasSize(4);
assertThat(mergedInner.testCases.stream().map(testCase -> testCase.name).collect(Collectors.toList())).containsExactly("testCase1", "testCase2", "testCase3", "testCase4");
}
Aggregations