Search in sources :

Example 1 with TestSuite

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)));
    }
}
Also used : TestSuiteStarted(jetbrains.buildServer.messages.serviceMessages.TestSuiteStarted) TestSuite(com.google.idea.blaze.base.run.smrunner.BlazeXmlSchema.TestSuite) TestCase(com.google.idea.blaze.base.run.smrunner.BlazeXmlSchema.TestCase) TestSuiteStartedEvent(com.intellij.execution.testframework.sm.runner.events.TestSuiteStartedEvent) TestSuiteFinishedEvent(com.intellij.execution.testframework.sm.runner.events.TestSuiteFinishedEvent)

Example 2 with TestSuite

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&#xA;&#xA;</system-out>", "      </testcase>", "  </testsuite>");
    assertThat(parsed).isNotNull();
}
Also used : TestSuite(com.google.idea.blaze.base.run.smrunner.BlazeXmlSchema.TestSuite) Test(org.junit.Test)

Example 3 with TestSuite

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);
}
Also used : TestStatus(com.google.idea.blaze.base.run.testlogs.BlazeTestResult.TestStatus) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) FileInputStream(java.io.FileInputStream) TestSuite(com.google.idea.blaze.base.run.smrunner.BlazeXmlSchema.TestSuite) Kind(com.google.idea.blaze.base.model.primitives.Kind) Objects(java.util.Objects) File(java.io.File)

Example 4 with TestSuite

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");
}
Also used : TestSuite(com.google.idea.blaze.base.run.smrunner.BlazeXmlSchema.TestSuite) TestCase(com.google.idea.blaze.base.run.smrunner.BlazeXmlSchema.TestCase) Test(org.junit.Test)

Example 5 with TestSuite

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");
}
Also used : TestCase(com.google.idea.blaze.base.run.smrunner.BlazeXmlSchema.TestCase) ImmutableList(com.google.common.collect.ImmutableList) ByteArrayInputStream(java.io.ByteArrayInputStream) RunWith(org.junit.runner.RunWith) Test(org.junit.Test) TestSuite(com.google.idea.blaze.base.run.smrunner.BlazeXmlSchema.TestSuite) JUnit4(org.junit.runners.JUnit4) Truth.assertThat(com.google.common.truth.Truth.assertThat) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) Joiner(com.google.common.base.Joiner) InputStream(java.io.InputStream) TestSuite(com.google.idea.blaze.base.run.smrunner.BlazeXmlSchema.TestSuite) Test(org.junit.Test)

Aggregations

TestSuite (com.google.idea.blaze.base.run.smrunner.BlazeXmlSchema.TestSuite)6 Test (org.junit.Test)4 TestCase (com.google.idea.blaze.base.run.smrunner.BlazeXmlSchema.TestCase)3 InputStream (java.io.InputStream)2 Joiner (com.google.common.base.Joiner)1 ImmutableList (com.google.common.collect.ImmutableList)1 Truth.assertThat (com.google.common.truth.Truth.assertThat)1 Kind (com.google.idea.blaze.base.model.primitives.Kind)1 TestStatus (com.google.idea.blaze.base.run.testlogs.BlazeTestResult.TestStatus)1 TestSuiteFinishedEvent (com.intellij.execution.testframework.sm.runner.events.TestSuiteFinishedEvent)1 TestSuiteStartedEvent (com.intellij.execution.testframework.sm.runner.events.TestSuiteStartedEvent)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 StandardCharsets (java.nio.charset.StandardCharsets)1 ArrayList (java.util.ArrayList)1 Objects (java.util.Objects)1 Collectors (java.util.stream.Collectors)1 TestSuiteStarted (jetbrains.buildServer.messages.serviceMessages.TestSuiteStarted)1 RunWith (org.junit.runner.RunWith)1