test notifications: make notification message more precise with failed/ignored numbers

This commit is contained in:
Anna Kozlova
2015-04-13 19:23:56 +02:00
parent b0437beb7e
commit 0b41be78f7
5 changed files with 10 additions and 126 deletions
@@ -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.
@@ -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);
}
}
@@ -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);
@@ -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);
}
}
@@ -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());
}