From 6e4a9866afa9989511fd4cb2d986bd4c264439ae Mon Sep 17 00:00:00 2001 From: anna Date: Wed, 8 Sep 2010 21:20:24 +0400 Subject: [PATCH] junit statistics: total labels --- .../execution/testframework/TestsUIUtil.java | 100 +++++++++++++----- .../execution/junit2/ui/StatisticsPanel.java | 27 +++-- 2 files changed, 92 insertions(+), 35 deletions(-) diff --git a/platform/testRunner/src/com/intellij/execution/testframework/TestsUIUtil.java b/platform/testRunner/src/com/intellij/execution/testframework/TestsUIUtil.java index d0ca3d51bad5..b04f9ea7952e 100644 --- a/platform/testRunner/src/com/intellij/execution/testframework/TestsUIUtil.java +++ b/platform/testRunner/src/com/intellij/execution/testframework/TestsUIUtil.java @@ -114,39 +114,81 @@ public class TestsUIUtil { String text; String balloonText; MessageType type; - if (root == null) { - balloonText = title = ExecutionBundle.message("test.not.started.progress.text"); - text = ""; - type = MessageType.WARNING; - } else{ - List allTests = Filter.LEAF.select(root.getAllTests()); - final List failed = Filter.DEFECTIVE_LEAF.select(allTests); - int failedCount = failed.size(); - final List notStarted = Filter.NOT_PASSED.select(allTests); - notStarted.removeAll(failed); - int notStartedCount = notStarted.size(); - int passedCount = allTests.size() - failedCount - notStartedCount; - if (failedCount > 0) { - title = ExecutionBundle.message("junit.runing.info.tests.failed.label"); - text = passedCount + " passed, " + failedCount + " failed" + (notStartedCount > 0 ? ", " + notStartedCount + " not started" : ""); - type = MessageType.ERROR; - } - else if (notStartedCount > 0) { - title = ExecutionBundle.message("junit.runing.info.failed.to.start.error.message"); - text = passedCount + " passed, " + notStartedCount + " not started" ; - type = MessageType.ERROR; - } - else { - title = ExecutionBundle.message("junit.runing.info.tests.passed.label"); - text = passedCount + " passed"; - type = MessageType.INFO; - } - balloonText = title + ": " + text; - } + TestResultPresentation testResultPresentation = new TestResultPresentation(root).getPresentation(); + type = testResultPresentation.getType(); + balloonText = testResultPresentation.getBalloonText(); + title = testResultPresentation.getTitle(); + text = testResultPresentation.getText(); if (!Comparing.strEqual(toolWindowManager.getActiveToolWindowId(), testRunDebugId)) { toolWindowManager.notifyByBalloon(testRunDebugId, type, balloonText, null, null); } SystemNotifications.getInstance().notify("TestRunner", title, text); } + + public static String getTestSummary(AbstractTestProxy proxy) { + return new TestResultPresentation(proxy).getPresentation().getBalloonText(); + } + + private static class TestResultPresentation { + private AbstractTestProxy myRoot; + private String myTitle; + private String myText; + private String myBalloonText; + private MessageType myType; + + public TestResultPresentation(AbstractTestProxy root) { + myRoot = root; + } + + public String getTitle() { + return myTitle; + } + + public String getText() { + return myText; + } + + public String getBalloonText() { + return myBalloonText; + } + + public MessageType getType() { + return myType; + } + + public TestResultPresentation getPresentation() { + if (myRoot == null) { + myBalloonText = myTitle = ExecutionBundle.message("test.not.started.progress.text"); + myText = ""; + myType = MessageType.WARNING; + } else{ + List allTests = Filter.LEAF.select(myRoot.getAllTests()); + final List failed = Filter.DEFECTIVE_LEAF.select(allTests); + int failedCount = failed.size(); + final List notStarted = Filter.NOT_PASSED.select(allTests); + notStarted.removeAll(failed); + int notStartedCount = notStarted.size(); + int passedCount = allTests.size() - failedCount - notStartedCount; + if (failedCount > 0) { + myTitle = ExecutionBundle.message("junit.runing.info.tests.failed.label"); + myText = passedCount + " passed, " + failedCount + " failed" + (notStartedCount > 0 ? ", " + notStartedCount + " not started" : ""); + myType = MessageType.ERROR; + } + else if (notStartedCount > 0) { + myTitle = ExecutionBundle.message("junit.runing.info.failed.to.start.error.message"); + myText = passedCount + " passed, " + notStartedCount + " not started" ; + myType = MessageType.ERROR; + } + else { + myTitle = ExecutionBundle.message("junit.runing.info.tests.passed.label"); + myText = passedCount + " passed"; + myType = MessageType.INFO; + } + myBalloonText = myTitle + ": " + myText; + } + return this; + } + + } } diff --git a/plugins/junit/src/com/intellij/execution/junit2/ui/StatisticsPanel.java b/plugins/junit/src/com/intellij/execution/junit2/ui/StatisticsPanel.java index 61a5bc21fe21..580d65514b6c 100644 --- a/plugins/junit/src/com/intellij/execution/junit2/ui/StatisticsPanel.java +++ b/plugins/junit/src/com/intellij/execution/junit2/ui/StatisticsPanel.java @@ -25,8 +25,8 @@ import com.intellij.execution.testframework.TestsUIUtil; import com.intellij.openapi.actionSystem.ActionPlaces; import com.intellij.openapi.actionSystem.DataProvider; import com.intellij.openapi.actionSystem.IdeActions; -import com.intellij.ui.PopupHandler; -import com.intellij.ui.TableUtil; +import com.intellij.openapi.ui.VerticalFlowLayout; +import com.intellij.ui.*; import com.intellij.ui.table.BaseTableView; import com.intellij.ui.table.TableView; import com.intellij.util.config.Storage; @@ -46,6 +46,8 @@ class StatisticsPanel extends JPanel implements DataProvider{ private JUnitRunningModel myModel; private final TableView myTable; private final Storage.PropertiesComponentStorage myStorage = new Storage.PropertiesComponentStorage("junit_statistics_table_columns"); + private SimpleColoredComponent myTotalLabel; + private SimpleColoredComponent myTimeLabel; public StatisticsPanel() { super(new BorderLayout(0, 0)); @@ -60,17 +62,30 @@ class StatisticsPanel extends JPanel implements DataProvider{ IdeActions.GROUP_TESTSTATISTICS_POPUP, ActionPlaces.TESTSTATISTICS_VIEW_POPUP); // add(myTestCaseInfo, BorderLayout.NORTH); - add(myTable, BorderLayout.CENTER); + add(ScrollPaneFactory.createScrollPane(myTable), BorderLayout.CENTER); + final JPanel eastPanel = new JPanel(new VerticalFlowLayout(VerticalFlowLayout.TOP, 0, 0, true, false)); + + myTotalLabel = new SimpleColoredComponent(); + eastPanel.add(myTotalLabel); + + myTimeLabel = new SimpleColoredComponent(); + eastPanel.add(myTimeLabel); + + add(eastPanel, BorderLayout.SOUTH); } private void updateStatistics() { myTable.setVisible(true); // myTestCaseInfo.setVisible(false); + TestProxy proxy = myCurrentTest; if (myCurrentTest.isLeaf() && myCurrentTest.getParent() != null) { - myChildInfo.updateStatistics(myCurrentTest.getParent()); - } else{ - myChildInfo.updateStatistics(myCurrentTest); + proxy = myCurrentTest.getParent(); } + myChildInfo.updateStatistics(proxy); + myTotalLabel.clear(); + myTotalLabel.append(TestsUIUtil.getTestSummary(proxy), SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES); + myTimeLabel.clear(); + myTimeLabel.append("Total time: " + Formatters.statisticsFor(proxy).getTime(), SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES); final int idx = myChildInfo.getIndexOf(myCurrentTest); TableUtil.selectRows(myTable, new int[]{idx}); TableUtil.scrollSelectionToVisible(myTable);