From 74fae70f41cde130ff39448ec2b5e2787a490c40 Mon Sep 17 00:00:00 2001 From: Sergey Simonchik Date: Tue, 10 Apr 2018 19:01:53 +0300 Subject: [PATCH] add test for auto 'testFinished' event for 'testIgnored' (IDEA-CR-31598) --- .../sm/runner/events/TestIgnoredEvent.java | 12 +++-- ...IdBasedToSMTRunnerEventsConvertorTest.java | 54 +++++++++++++++++-- 2 files changed, 57 insertions(+), 9 deletions(-) diff --git a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/events/TestIgnoredEvent.java b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/events/TestIgnoredEvent.java index 500cecb109de..ea090421a46c 100644 --- a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/events/TestIgnoredEvent.java +++ b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/events/TestIgnoredEvent.java @@ -26,14 +26,16 @@ public class TestIgnoredEvent extends TreeNodeEvent { private final String myStacktrace; public TestIgnoredEvent(@NotNull String testName, @NotNull String ignoreComment, @Nullable String stacktrace) { - super(testName, null); - myIgnoreComment = ignoreComment; - myStacktrace = stacktrace; + this(testName, null, ignoreComment, stacktrace); } public TestIgnoredEvent(@NotNull TestIgnored testIgnored, @Nullable String stacktrace) { - super(testIgnored.getTestName(), TreeNodeEvent.getNodeId(testIgnored)); - myIgnoreComment = testIgnored.getIgnoreComment(); + this(testIgnored.getTestName(), TreeNodeEvent.getNodeId(testIgnored), testIgnored.getIgnoreComment(), stacktrace); + } + + public TestIgnoredEvent(@Nullable String name, @Nullable String id, @Nullable String ignoreComment, @Nullable String stacktrace) { + super(name, id); + myIgnoreComment = ignoreComment; myStacktrace = stacktrace; } diff --git a/platform/smRunner/testSrc/com/intellij/execution/testframework/sm/runner/GeneralIdBasedToSMTRunnerEventsConvertorTest.java b/platform/smRunner/testSrc/com/intellij/execution/testframework/sm/runner/GeneralIdBasedToSMTRunnerEventsConvertorTest.java index eaca233b754b..cb09a89ff4dc 100644 --- a/platform/smRunner/testSrc/com/intellij/execution/testframework/sm/runner/GeneralIdBasedToSMTRunnerEventsConvertorTest.java +++ b/platform/smRunner/testSrc/com/intellij/execution/testframework/sm/runner/GeneralIdBasedToSMTRunnerEventsConvertorTest.java @@ -15,23 +15,32 @@ */ package com.intellij.execution.testframework.sm.runner; -import com.intellij.execution.testframework.sm.runner.events.TestFailedEvent; -import com.intellij.execution.testframework.sm.runner.events.TestStartedEvent; -import com.intellij.execution.testframework.sm.runner.events.TestSuiteStartedEvent; -import com.intellij.execution.testframework.sm.runner.events.TreeNodeEvent; +import com.intellij.execution.testframework.TestConsoleProperties; +import com.intellij.execution.testframework.sm.runner.events.*; +import com.intellij.execution.testframework.sm.runner.ui.SMTRunnerConsoleView; +import com.intellij.execution.testframework.sm.runner.ui.SMTestRunnerResultsForm; import com.intellij.openapi.util.Disposer; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; public class GeneralIdBasedToSMTRunnerEventsConvertorTest extends BaseSMTRunnerTestCase { + private SMTRunnerConsoleView myConsole; private GeneralIdBasedToSMTRunnerEventsConvertor myEventsProcessor; private SMTestProxy.SMRootTestProxy myRootProxy; + private SMTestRunnerResultsForm myResultsViewer; @Override protected void setUp() throws Exception { super.setUp(); + + TestConsoleProperties consoleProperties = createConsoleProperties(); + myConsole = new SMTRunnerConsoleView(consoleProperties); + myConsole.initUI(); + myResultsViewer = myConsole.getResultsViewer(); + myRootProxy = new SMTestProxy.SMRootTestProxy(); myEventsProcessor = new GeneralIdBasedToSMTRunnerEventsConvertor(getProject(), myRootProxy, "test"); + myEventsProcessor.addEventsListener(myResultsViewer); myEventsProcessor.onStartTesting(); } @@ -39,6 +48,7 @@ public class GeneralIdBasedToSMTRunnerEventsConvertorTest extends BaseSMTRunnerT protected void tearDown() throws Exception { try { Disposer.dispose(myEventsProcessor); + Disposer.dispose(myConsole); } finally { super.tearDown(); @@ -84,6 +94,27 @@ public class GeneralIdBasedToSMTRunnerEventsConvertorTest extends BaseSMTRunnerT assertTrue(suiteProxy.isInProgress()); } + public void testIgnoredEvent() { + onSuiteStarted("Suite", null, "1", TreeNodeEvent.ROOT_NODE_ID); + SMTestProxy suite = validateSuite("1", "Suite", null, myRootProxy); + onTestStarted("testA", null, "A", "1", true); + SMTestProxy testA = validateTest("A", "testA", null, true, suite); + onTestIgnored("A"); + validateTestIgnored("A", testA); + assertFalse(testA.isInProgress()); + assertTrue(suite.isInProgress()); + assertEquals(1, myResultsViewer.getFinishedTestCount()); + onTestFinished("A", null); + assertEquals(1, myResultsViewer.getFinishedTestCount()); + + onTestStarted("testB", null, "B", "1", true); + SMTestProxy testB = validateTest("B", "testB", null, true, suite); + assertEquals(1, myResultsViewer.getFinishedTestCount()); + onTestIgnored("B"); + assertEquals(2, myResultsViewer.getFinishedTestCount()); + validateTestIgnored("B", testB); + } + @NotNull private SMTestProxy validateSuite(@NotNull String id, @NotNull String expectedName, @@ -129,6 +160,14 @@ public class GeneralIdBasedToSMTRunnerEventsConvertorTest extends BaseSMTRunnerT return test; } + private void validateTestIgnored(@NotNull String id, @NotNull SMTestProxy expectedTestProxy) { + SMTestProxy test = myEventsProcessor.findProxyById(id); + assertEquals(expectedTestProxy, test); + assertFalse(test.isSuite()); + assertTrue(test.isFinal()); + assertTrue(test.isIgnored()); + } + private void onSuiteStarted(@NotNull String suiteName, @Nullable String metainfo, @NotNull String id, @NotNull String parentId) { myEventsProcessor.onSuiteStarted(new TestSuiteStartedEvent(suiteName, id, parentId, null, metainfo, null, null, false)); } @@ -141,9 +180,16 @@ public class GeneralIdBasedToSMTRunnerEventsConvertorTest extends BaseSMTRunnerT myEventsProcessor.onTestStarted(new TestStartedEvent(testName, id, parentId, null, metainfo, null, null, running)); } + private void onTestFinished(@NotNull String id, @Nullable Long duration) { + myEventsProcessor.onTestFinished(new TestFinishedEvent(null, id, duration)); + } + private void onTestFailed(@NotNull String id, @NotNull String errorMessage, int durationMillis) { myEventsProcessor.onTestFailure(new TestFailedEvent(null, id, errorMessage, null, false, null, null, null, null, false, false, durationMillis)); } + private void onTestIgnored(@NotNull String id) { + myEventsProcessor.onTestIgnored(new TestIgnoredEvent(null, id, null, null)); + } }