From 0b41be78f7b96e9f9fb21895473fc7d739cb7223 Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Mon, 13 Apr 2015 19:19:05 +0200 Subject: [PATCH] test notifications: make notification message more precise with failed/ignored numbers --- .../messages/SMTestsRunnerBundle.properties | 11 +- .../ui/SMTRunnerNotificationsHandler.java | 120 +----------------- .../execution/testframework/TestsUIUtil.java | 2 + .../junit2/ui/TestsPacketsReceiver.java | 2 - .../testng/ui/TestNGResults.java | 1 - 5 files changed, 10 insertions(+), 126 deletions(-) diff --git a/platform/platform-resources-en/src/messages/SMTestsRunnerBundle.properties b/platform/platform-resources-en/src/messages/SMTestsRunnerBundle.properties index 51a4ef7ed62d..43a78f4263a2 100644 --- a/platform/platform-resources-en/src/messages/SMTestsRunnerBundle.properties +++ b/platform/platform-resources-en/src/messages/SMTestsRunnerBundle.properties @@ -46,13 +46,4 @@ sm.test.runner.magnitude.assertion.failed.title=Assertion failed sm.test.runner.magnitude.testerror.title=Error sm.test.runner.states.suite.is.empty=Empty test suite. -sm.test.runner.states.test.is.ignored=Test ignored. - -sm.test.runner.notifications.tests.passed=Tests passed -sm.test.runner.notifications.tests.passed.with.errors=Tests passed with errors -sm.test.runner.notifications.tests.failed=Tests failed -sm.test.runner.notifications.tests.failed.with.errors=Tests failed with errors -sm.test.runner.notifications.tests.skipped=Tests skipped -sm.test.runner.notifications.tests.skipped.with.errors=Tests skipped with errors -sm.test.runner.notifications.tests.not.run=Tests were not started -sm.test.runner.notifications.tests.not.run.with.errors=Tests were not started with errors. Errors occurred +sm.test.runner.states.test.is.ignored=Test ignored. \ No newline at end of file diff --git a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/ui/SMTRunnerNotificationsHandler.java b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/ui/SMTRunnerNotificationsHandler.java index 5a1a19c1c67a..d29f3bd81b05 100644 --- a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/ui/SMTRunnerNotificationsHandler.java +++ b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/ui/SMTRunnerNotificationsHandler.java @@ -16,139 +16,33 @@ package com.intellij.execution.testframework.sm.runner.ui; import com.intellij.execution.testframework.TestConsoleProperties; -import com.intellij.execution.testframework.TestStatusListener; import com.intellij.execution.testframework.TestsUIUtil; -import com.intellij.execution.testframework.sm.SMTestsRunnerBundle; import com.intellij.execution.testframework.sm.runner.SMTRunnerConsoleProperties; import com.intellij.execution.testframework.sm.runner.SMTRunnerEventsAdapter; import com.intellij.execution.testframework.sm.runner.SMTestProxy; -import com.intellij.execution.testframework.sm.runner.states.TestStateInfo; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.ui.MessageType; -import com.intellij.openapi.util.Comparing; -import com.intellij.openapi.wm.ToolWindowId; -import com.intellij.openapi.wm.ToolWindowManager; -import com.intellij.ui.SystemNotifications; import org.jetbrains.annotations.NotNull; -import javax.swing.*; - /** * @author Roman Chernyatchik */ public class SMTRunnerNotificationsHandler extends SMTRunnerEventsAdapter { private final TestConsoleProperties myConsoleProperties; - //private boolean myFirstDefectWasFound; + private boolean myStarted = false; public SMTRunnerNotificationsHandler(@NotNull final TestConsoleProperties consoleProperties) { myConsoleProperties = consoleProperties; } public void onTestingStarted(@NotNull SMTestProxy.SMRootTestProxy testsRoot) { - //myFirstDefectWasFound = false; + myStarted = true; } public void onTestingFinished(@NotNull SMTestProxy.SMRootTestProxy testsRoot) { - final String msg; - final MessageType type; - - final TestStateInfo.Magnitude magnitude = testsRoot.getMagnitudeInfo(); - //noinspection EnumSwitchStatementWhichMissesCases - switch (magnitude) { - case SKIPPED_INDEX: - case IGNORED_INDEX: - msg = testsRoot.hasErrors() ? SMTestsRunnerBundle.message("sm.test.runner.notifications.tests.skipped.with.errors") - : SMTestsRunnerBundle.message("sm.test.runner.notifications.tests.skipped"); - - type = MessageType.WARNING; - break; - - case NOT_RUN_INDEX: - msg = testsRoot.hasErrors() ? SMTestsRunnerBundle.message("sm.test.runner.notifications.tests.not.run.with.errors") - : SMTestsRunnerBundle.message("sm.test.runner.notifications.tests.not.run"); - type = MessageType.WARNING; - break; - - case FAILED_INDEX: - case ERROR_INDEX: - msg = testsRoot.hasErrors() ? SMTestsRunnerBundle.message("sm.test.runner.notifications.tests.failed.with.errors") - : SMTestsRunnerBundle.message("sm.test.runner.notifications.tests.failed"); - type = MessageType.ERROR; - break; - case COMPLETE_INDEX: - if (testsRoot.getChildren().size() == 0 && !testsRoot.isLeaf()) { - msg = testsRoot.hasErrors() ? SMTestsRunnerBundle.message("sm.test.runner.ui.tests.tree.presentation.labels.no.tests.were.found.with.errors") - : testsRoot.isTestsReporterAttached() - ? SMTestsRunnerBundle.message("sm.test.runner.ui.tests.tree.presentation.labels.no.tests.were.found") - : SMTestsRunnerBundle.message("sm.test.runner.ui.tests.tree.presentation.labels.test.reporter.not.attached"); - type = MessageType.ERROR; - break; - } else if (testsRoot.isEmptySuite()) { - if (myConsoleProperties instanceof SMTRunnerConsoleProperties && ((SMTRunnerConsoleProperties)myConsoleProperties).fixEmptySuite()) { - return; - } - msg = SMTestsRunnerBundle.message("sm.test.runner.ui.tests.tree.presentation.labels.empty.test.suite"); - type = MessageType.WARNING; - break; - } - // else same as: PASSED_INDEX - case PASSED_INDEX: - msg = testsRoot.hasErrors() ? SMTestsRunnerBundle.message("sm.test.runner.notifications.tests.passed.with.errors") - : SMTestsRunnerBundle.message("sm.test.runner.notifications.tests.passed"); - type = MessageType.INFO; - break; - - default: - msg = null; - type = null; + if (testsRoot.isEmptySuite() && + myConsoleProperties instanceof SMTRunnerConsoleProperties && + ((SMTRunnerConsoleProperties)myConsoleProperties).fixEmptySuite()) { + return; } - - TestStatusListener.notifySuiteFinished(testsRoot, myConsoleProperties.getProject()); - - if (msg != null) { - notify(msg, type, testsRoot); - } - } - - public void onTestFailed(@NotNull SMTestProxy test) { - // TODO : if user doesn't close this balloon then user will not see 'tests failed' balloon - //if (!myFirstDefectWasFound) { - // // notify about defect on the fly - // if (test.isDefect()) { - // final TestStateInfo.Magnitude magnitude = test.getMagnitudeInfo(); - // //noinspection EnumSwitchStatementWhichMissesCases - // switch (magnitude) { - // case FAILED_INDEX: - // case ERROR_INDEX: - // myFirstDefectWasFound = true; - // notify("Tests will fail", MessageType.WARNING); - // break; - // default: - // // Do nothing - // } - // } - //} - } - - private void notify(final String msg, final MessageType type, final SMTestProxy.SMRootTestProxy testsRoot) { - SwingUtilities.invokeLater(new Runnable() { - public void run() { - final Project project = myConsoleProperties.getProject(); - if ( project.isDisposed()) { - return; - } - - if (myConsoleProperties == null) { - return; - } - final String testRunDebugId = myConsoleProperties.isDebug() ? ToolWindowId.DEBUG : ToolWindowId.RUN; - final ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(project); - if (!Comparing.strEqual(toolWindowManager.getActiveToolWindowId(), testRunDebugId)) { - toolWindowManager.notifyByBalloon(testRunDebugId, type, msg, null, null); - } - TestsUIUtil.NOTIFICATION_GROUP.createNotification(msg, type).notify(project); - SystemNotifications.getInstance().notify("TestRunner", msg, TestsUIUtil.getTestShortSummary(testsRoot)); - } - }); + TestsUIUtil.notifyByBalloon(myConsoleProperties.getProject(), myStarted, testsRoot, myConsoleProperties, null); } } \ No newline at end of file diff --git a/platform/testRunner/src/com/intellij/execution/testframework/TestsUIUtil.java b/platform/testRunner/src/com/intellij/execution/testframework/TestsUIUtil.java index 59e30a064581..177ca6793d49 100644 --- a/platform/testRunner/src/com/intellij/execution/testframework/TestsUIUtil.java +++ b/platform/testRunner/src/com/intellij/execution/testframework/TestsUIUtil.java @@ -115,6 +115,8 @@ public class TestsUIUtil { if (project.isDisposed()) return; if (properties == null) return; + TestStatusListener.notifySuiteFinished(root, properties.getProject()); + final String testRunDebugId = properties.isDebug() ? ToolWindowId.DEBUG : ToolWindowId.RUN; final ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(project); diff --git a/plugins/junit/src/com/intellij/execution/junit2/ui/TestsPacketsReceiver.java b/plugins/junit/src/com/intellij/execution/junit2/ui/TestsPacketsReceiver.java index 9970bce03319..0a8f7655262a 100644 --- a/plugins/junit/src/com/intellij/execution/junit2/ui/TestsPacketsReceiver.java +++ b/plugins/junit/src/com/intellij/execution/junit2/ui/TestsPacketsReceiver.java @@ -33,7 +33,6 @@ import com.intellij.execution.junit2.ui.model.JUnitRunningModel; import com.intellij.execution.junit2.ui.properties.JUnitConsoleProperties; import com.intellij.execution.testframework.AbstractTestProxy; import com.intellij.execution.testframework.Printable; -import com.intellij.execution.testframework.TestStatusListener; import com.intellij.openapi.Disposable; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diagnostic.Logger; @@ -220,7 +219,6 @@ public class TestsPacketsReceiver implements OutputPacketProcessor, Disposable { final JUnitRunningModel model = getModel(); if (model != null) { model.getNotifier().fireRunnerStateChanged(new CompletionEvent(true, reader.readInt())); - TestStatusListener.notifySuiteFinished(model.getRoot(), model.getProject()); terminateStillRunning(model); } } diff --git a/plugins/testng/src/com/theoryinpractice/testng/ui/TestNGResults.java b/plugins/testng/src/com/theoryinpractice/testng/ui/TestNGResults.java index da30e818fc73..7906522d159f 100644 --- a/plugins/testng/src/com/theoryinpractice/testng/ui/TestNGResults.java +++ b/plugins/testng/src/com/theoryinpractice/testng/ui/TestNGResults.java @@ -385,7 +385,6 @@ public class TestNGResults extends TestResultsPanel implements TestFrameworkRunn myStatusLine.setStatusColor(ColorProgressBar.GREEN); } rootNode.setInProgress(false); - TestStatusListener.notifySuiteFinished(rootNode, project); if (TestNGConsoleProperties.SELECT_FIRST_DEFECT.value(myProperties)) { selectTest(rootNode.getFirstDefect()); }