diff --git a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/GeneralTestEventsProcessor.java b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/GeneralTestEventsProcessor.java index cb7e6a5d63de..83904864ab1a 100644 --- a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/GeneralTestEventsProcessor.java +++ b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/GeneralTestEventsProcessor.java @@ -26,4 +26,15 @@ public interface GeneralTestEventsProcessor extends Disposable { void onSuiteFinished(final String suiteName); void onUncapturedOutput(final String text, final Key outputType); + + // Custom progress statistics + + /** + * @param categoryName If isn't empty then progress statistics will use only custom start/failed events. + * If name is null statistics will be switched to normal mode + * @param testCount - 0 will be considered as unknown tests number + */ + void onCustomProgressTestsCategory(@Nullable final String categoryName, final int testCount); + void onCustomProgressTestStarted(); + void onCustomProgressTestFailed(); } \ No newline at end of file diff --git a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/GeneralToSMTRunnerEventsConvertor.java b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/GeneralToSMTRunnerEventsConvertor.java index 61664dff66f3..975242b04afe 100644 --- a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/GeneralToSMTRunnerEventsConvertor.java +++ b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/GeneralToSMTRunnerEventsConvertor.java @@ -183,6 +183,31 @@ public class GeneralToSMTRunnerEventsConvertor implements GeneralTestEventsProce }); } + public void onCustomProgressTestsCategory(@Nullable final String categoryName, + final int testCount) { + SMRunnerUtil.addToInvokeLater(new Runnable() { + public void run() { + fireOnCustomProgressTestsCategory(categoryName, testCount); + } + }); + } + + public void onCustomProgressTestStarted() { + SMRunnerUtil.addToInvokeLater(new Runnable() { + public void run() { + fireOnCustomProgressTestStarted(); + } + }); + } + + public void onCustomProgressTestFailed() { + SMRunnerUtil.addToInvokeLater(new Runnable() { + public void run() { + fireOnCustomProgressTestFailed(); + } + }); + } + public void onTestFailure(final String testName, final String localizedMessage, final String stackTrace, final boolean isTestError) { @@ -377,6 +402,25 @@ public class GeneralToSMTRunnerEventsConvertor implements GeneralTestEventsProce } } + + private void fireOnCustomProgressTestsCategory(@Nullable final String categoryName, int testCount) { + for (SMTRunnerEventsListener listener : myEventsListeners) { + listener.onCustomProgressTestsCategory(categoryName, testCount); + } + } + + private void fireOnCustomProgressTestStarted() { + for (SMTRunnerEventsListener listener : myEventsListeners) { + listener.onCustomProgressTestStarted(); + } + } + + private void fireOnCustomProgressTestFailed() { + for (SMTRunnerEventsListener listener : myEventsListeners) { + listener.onCustomProgressTestFailed(); + } + } + /* * Remove listeners, etc */ diff --git a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/OutputToGeneralTestEventsConverter.java b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/OutputToGeneralTestEventsConverter.java index 6963509ef41d..45841ec4ff44 100644 --- a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/OutputToGeneralTestEventsConverter.java +++ b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/OutputToGeneralTestEventsConverter.java @@ -12,6 +12,7 @@ import org.jetbrains.annotations.Nullable; import java.text.ParseException; import java.util.ArrayList; import java.util.List; +import java.util.Map; /** * @author Roman Chernyatchik @@ -181,6 +182,37 @@ public class OutputToGeneralTestEventsConverter implements ProcessOutputConsumer } } + private void fireOnTestFinished(final String testName, final int duration) { + // local variable is used to prevent concurrent modification + final GeneralTestEventsProcessor processor = myProcessor; + if (processor != null) { + processor.onTestFinished(testName, duration); + } + } + + private void fireOnCustomProgressTestsCategory(@NotNull final String categoryName, int testsCount) { + final GeneralTestEventsProcessor processor = myProcessor; + if (processor != null) { + final boolean disableCustomMode = StringUtil.isEmpty(categoryName); + processor.onCustomProgressTestsCategory(disableCustomMode ? null : categoryName, + disableCustomMode ? 0 : testsCount); + } + } + + private void fireOnCustomProgressTestStarted() { + final GeneralTestEventsProcessor processor = myProcessor; + if (processor != null) { + processor.onCustomProgressTestStarted(); + } + } + + private void fireOnCustomProgressTestFailed() { + final GeneralTestEventsProcessor processor = myProcessor; + if (processor != null) { + processor.onCustomProgressTestFailed(); + } + } + private void fireOnTestOutput(final String testName, final String text, final boolean stdOut) { // local variable is used to prevent concurrent modification final GeneralTestEventsProcessor processor = myProcessor; @@ -205,14 +237,6 @@ public class OutputToGeneralTestEventsConverter implements ProcessOutputConsumer } } - private void fireOnTestFinished(final String testName, final int duration) { - // local variable is used to prevent concurrent modification - final GeneralTestEventsProcessor processor = myProcessor; - if (processor != null) { - processor.onTestFinished(testName, duration); - } - } - private void fireOnSuiteStarted(final String suiteName, @Nullable final String locationUrl) { // local variable is used to prevent concurrent modification final GeneralTestEventsProcessor processor = myProcessor; @@ -237,6 +261,12 @@ public class OutputToGeneralTestEventsConverter implements ProcessOutputConsumer @NonNls private static final String ATTR_KEY_LOCATION_URL = "location"; @NonNls private static final String ATTR_KEY_STACKTRACE_DETAILS = "details"; + @NonNls public static final String CUSTOM_STATUS = "customProgressStatus"; + @NonNls private static final String ATTR_KEY_TEST_TYPE = "type"; + @NonNls private static final String ATTR_KEY_TESTS_CATEGORY = "testsCategory"; + @NonNls private static final String ATTR_VAL_TEST_STARTED = "testStarted"; + @NonNls private static final String ATTR_VAL_TEST_FAILED = "testFailed"; + public void visitTestSuiteStarted(@NotNull final TestSuiteStarted suiteStarted) { final String locationUrl = suiteStarted.getAttributes().get(ATTR_KEY_LOCATION_URL); fireOnSuiteStarted(suiteStarted.getSuiteName(), locationUrl); @@ -324,6 +354,8 @@ public class OutputToGeneralTestEventsConverter implements ProcessOutputConsumer if (KEY_TESTS_COUNT.equals(name)) { processTestCountInSuite(msg); + } else if (CUSTOM_STATUS.equals(name)) { + processCustomStatus(msg); } else { //Do nothing } @@ -331,13 +363,38 @@ public class OutputToGeneralTestEventsConverter implements ProcessOutputConsumer private void processTestCountInSuite(final ServiceMessage msg) { final String countStr = msg.getAttributes().get(ATTR_KEY_TEST_COUNT); + fireOnTestsCountInSuite(convertToInt(countStr)); + } + + private int convertToInt(String countStr) { int count = 0; try { count = Integer.parseInt(countStr); } catch (NumberFormatException ex) { LOG.error(ex); } - fireOnTestsCountInSuite(count); + return count; + } + + private void processCustomStatus(final ServiceMessage msg) { + final Map attrs = msg.getAttributes(); + final String msgType = attrs.get(ATTR_KEY_TEST_TYPE); + if (msgType != null) { + if (msgType.equals(ATTR_VAL_TEST_STARTED)) { + fireOnCustomProgressTestStarted(); + } else if (msgType.equals(ATTR_VAL_TEST_FAILED)) { + fireOnCustomProgressTestFailed(); + } + return; + } + final String testsCategory = attrs.get(ATTR_KEY_TESTS_CATEGORY); + if (testsCategory != null) { + final String countStr = msg.getAttributes().get(ATTR_KEY_TEST_COUNT); + fireOnCustomProgressTestsCategory(testsCategory, convertToInt(countStr)); + + //noinspection UnnecessaryReturnStatement + return; + } } } } diff --git a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/SMTRunnerEventsAdapter.java b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/SMTRunnerEventsAdapter.java index c03b5a3c1eb8..de1cf43c707b 100644 --- a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/SMTRunnerEventsAdapter.java +++ b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/SMTRunnerEventsAdapter.java @@ -1,6 +1,7 @@ package com.intellij.execution.testframework.sm.runner; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; /** * @author Roman Chernyatchik @@ -17,4 +18,10 @@ public class SMTRunnerEventsAdapter implements SMTRunnerEventsListener { public void onSuiteStarted(@NotNull final SMTestProxy suite) {} public void onSuiteFinished(@NotNull final SMTestProxy suite) {} + + // Custom progress status + + public void onCustomProgressTestsCategory(@Nullable String categoryName, final int testCount) {} + public void onCustomProgressTestStarted() {} + public void onCustomProgressTestFailed() {} } diff --git a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/SMTRunnerEventsListener.java b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/SMTRunnerEventsListener.java index 3828dc8f815a..61931b938dc4 100644 --- a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/SMTRunnerEventsListener.java +++ b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/SMTRunnerEventsListener.java @@ -1,6 +1,7 @@ package com.intellij.execution.testframework.sm.runner; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; /** * @author Roman Chernyatchik @@ -30,4 +31,15 @@ public interface SMTRunnerEventsListener { void onSuiteFinished(@NotNull SMTestProxy suite); void onSuiteStarted(@NotNull SMTestProxy suite); + + // Custom progress statistics + + /** + * @param categoryName If isn't empty then progress statistics will use only custom start/failed events. + * If name is empty string statistics will be switched to normal mode + * @param testCount - 0 will be considered as unknown tests number + */ + void onCustomProgressTestsCategory(@Nullable final String categoryName, final int testCount); + void onCustomProgressTestStarted(); + void onCustomProgressTestFailed(); } diff --git a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/ui/SMTestRunnerResultsForm.java b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/ui/SMTestRunnerResultsForm.java index 9618e5dd22c5..409b62c1a5fa 100644 --- a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/ui/SMTestRunnerResultsForm.java +++ b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/ui/SMTestRunnerResultsForm.java @@ -33,6 +33,8 @@ import java.awt.event.InputEvent; import java.awt.event.KeyEvent; import java.util.ArrayList; import java.util.List; +import java.util.Set; +import java.util.HashSet; /** * @author: Roman Chernyatchik @@ -64,6 +66,9 @@ public class SMTestRunnerResultsForm extends TestResultsPanel implements TestFra private long myEndTime; private StatisticsPanel myStatisticsPane; + // custom progress + private String myCurrentCustomProgressCategory; + private Set myMentionedCategories = new HashSet(); public SMTestRunnerResultsForm(final RunConfigurationBase runConfiguration, @NotNull final JComponent console, @@ -201,9 +206,7 @@ public class SMTestRunnerResultsForm extends TestResultsPanel implements TestFra } public void onTestsCountInSuite(final int count) { - //This is for beter support groups of TestSuites - //Each group notifies about it's size - myTestsTotal += count; + updateCountersAndProgressOnTestCount(count, false); } /** @@ -213,35 +216,15 @@ public class SMTestRunnerResultsForm extends TestResultsPanel implements TestFra * @param testProxy Proxy */ public void onTestStarted(@NotNull final SMTestProxy testProxy) { - // Counters - myTestsCurrentCount++; - - // fix total count if it is corrupted - // but if test count wasn't set at all let's process such case separately - if (myTestsCurrentCount > myTestsTotal && myTestsTotal != 0) { - myTestsTotal = myTestsCurrentCount; - } - - // update progress - if (myTestsTotal != 0) { - // if total is set - myStatusLine.setFraction((double)myTestsCurrentCount / myTestsTotal); - } else { - // just set progress in the middle to show user that tests are running - myStatusLine.setFraction(0.5); - } + updateCountersAndProgressOnTestStarted(false); _addTestOrSuite(testProxy); - - updateStatusLabel(); - fireOnTestNodeAdded(testProxy); } public void onTestFailed(@NotNull final SMTestProxy test) { - myTestsFailuresCount++; - updateStatusLabel(); + updateCountersAndProgressOnTestFailed(false); } public void onTestIgnored(@NotNull final SMTestProxy test) { @@ -259,6 +242,19 @@ public class SMTestRunnerResultsForm extends TestResultsPanel implements TestFra _addTestOrSuite(newSuite); } + public void onCustomProgressTestsCategory(@Nullable String categoryName, int testCount) { + myCurrentCustomProgressCategory = categoryName; + updateCountersAndProgressOnTestCount(testCount, true); + } + + public void onCustomProgressTestStarted() { + updateCountersAndProgressOnTestStarted(true); + } + + public void onCustomProgressTestFailed() { + updateCountersAndProgressOnTestFailed(true); + } + public void onTestFinished(@NotNull final SMTestProxy test) { //Do nothing } @@ -354,10 +350,18 @@ public class SMTestRunnerResultsForm extends TestResultsPanel implements TestFra return myTestsCurrentCount; } + protected int getTestsFailuresCount() { + return myTestsFailuresCount; + } + protected int getTestsTotal() { return myTestsTotal; } + public Set getMentionedCategories() { + return myMentionedCategories; + } + protected long getStartTime() { return myStartTime; } @@ -417,7 +421,7 @@ public class SMTestRunnerResultsForm extends TestResultsPanel implements TestFra } myStatusLine.setText(TestsPresentationUtil.getProgressStatus_Text(myStartTime, myEndTime, myTestsTotal, myTestsCurrentCount, - myTestsFailuresCount)); + myTestsFailuresCount, myMentionedCategories)); } /** @@ -459,6 +463,54 @@ public class SMTestRunnerResultsForm extends TestResultsPanel implements TestFra } } + private void updateCountersAndProgressOnTestCount(final int count, final boolean isCustomMessage) { + if (!isModeConsistent(isCustomMessage)) return; + + //This is for beter support groups of TestSuites + //Each group notifies about it's size + myTestsTotal += count; + updateStatusLabel(); + } + + private void updateCountersAndProgressOnTestStarted(final boolean isCustomMessage) { + if (!isModeConsistent(isCustomMessage)) return; + + // for mixed tests results : mention category only if it contained tests + myMentionedCategories.add(myCurrentCustomProgressCategory != null ? myCurrentCustomProgressCategory : TestsPresentationUtil.DEFAULT_TESTS_CATEGORY); + + // Counters + myTestsCurrentCount++; + + // fix total count if it is corrupted + // but if test count wasn't set at all let's process such case separately + if (myTestsCurrentCount > myTestsTotal && myTestsTotal != 0) { + myTestsTotal = myTestsCurrentCount; + } + + // update progress + if (myTestsTotal != 0) { + // if total is set + myStatusLine.setFraction((double)myTestsCurrentCount / myTestsTotal); + } else { + // just set progress in the middle to show user that tests are running + myStatusLine.setFraction(0.5); + } + updateStatusLabel(); + } + + private void updateCountersAndProgressOnTestFailed(final boolean isCustomMessage) { + if (!isModeConsistent(isCustomMessage)) return; + + myTestsFailuresCount++; + updateStatusLabel(); + } + + private boolean isModeConsistent(boolean isCustomMessage) { + // check that we are in consistent mode + return isCustomMessage != (myCurrentCustomProgressCategory == null); + } + + private static class MyFocusTraversalPolicy extends FocusTraversalPolicy { final List myComponents; diff --git a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/ui/TestsPresentationUtil.java b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/ui/TestsPresentationUtil.java index d6c246eda35f..91c933a2b46b 100644 --- a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/ui/TestsPresentationUtil.java +++ b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/ui/TestsPresentationUtil.java @@ -9,6 +9,7 @@ import com.intellij.execution.testframework.sm.runner.states.TestStateInfo; import com.intellij.execution.testframework.ui.TestsProgressAnimator; import com.intellij.ui.ColoredTableCellRenderer; import com.intellij.ui.SimpleTextAttributes; +import com.intellij.openapi.util.text.StringUtil; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -16,6 +17,7 @@ import org.jetbrains.annotations.Nullable; import javax.swing.*; import java.awt.*; import java.util.List; +import java.util.Set; /** * @author Roman Chernyatchik @@ -42,6 +44,7 @@ public class TestsPresentationUtil { @NonNls private static final String RESULTS_NO_TESTS = SMTestsRunnerBundle.message( "sm.test.runner.ui.tabs.statistics.columns.results.no.tests"); @NonNls private static final String UNKNOWN_TESTS_COUNT = "<...>"; + @NonNls static final String DEFAULT_TESTS_CATEGORY = "Tests"; private TestsPresentationUtil() { @@ -51,7 +54,8 @@ public class TestsPresentationUtil { final long endTime, final int testsTotal, final int testsCount, - final int failuresCount) { + final int failuresCount, + @Nullable final Set allCategories) { final StringBuilder sb = new StringBuilder(); if (endTime == 0) { sb.append(SMTestsRunnerBundle.message("sm.test.runner.ui.tests.tree.presentation.labels.running")); @@ -59,6 +63,35 @@ public class TestsPresentationUtil { sb.append(SMTestsRunnerBundle.message("sm.test.runner.ui.tests.tree.presentation.labels.done")); } + if (allCategories != null) { + // if all categories is just one default tests category - let's do not add prefixes + + if (allCategories.size() > 1 + || (allCategories.size() == 1 && !DEFAULT_TESTS_CATEGORY.equals(allCategories.iterator().next()))) { + + sb.append(' '); + boolean first = true; + for (String category : allCategories) { + if (StringUtil.isEmpty(category)) { + continue; + } + + // separator + if (!first) { + sb.append(", "); + + } + + // first symbol - to lower case + final char firstChar = category.charAt(0); + sb.append(first ? firstChar : Character.toLowerCase(firstChar)); + + sb.append(category.substring(1)); + first = false; + } + } + } + sb.append(' ').append(testsCount).append(' '); sb.append(SMTestsRunnerBundle.message("sm.test.runner.ui.tests.tree.presentation.labels.of")); sb.append(' ').append(testsTotal != 0 ? testsTotal : UNKNOWN_TESTS_COUNT); diff --git a/platform/smRunner/testSrc/com/intellij/execution/testframework/sm/runner/ui/SMTestRunnerResultsFormTest.java b/platform/smRunner/testSrc/com/intellij/execution/testframework/sm/runner/ui/SMTestRunnerResultsFormTest.java index a25dc1c0cdd4..4a0d7bb2e4bd 100644 --- a/platform/smRunner/testSrc/com/intellij/execution/testframework/sm/runner/ui/SMTestRunnerResultsFormTest.java +++ b/platform/smRunner/testSrc/com/intellij/execution/testframework/sm/runner/ui/SMTestRunnerResultsFormTest.java @@ -172,7 +172,7 @@ public class SMTestRunnerResultsFormTest extends BaseSMTRunnerTestCase { myResultsViewer.setShowStatisticForProxyHandler(new PropagateSelectionHandler() { public void handlePropagateSelectionRequest(@Nullable final SMTestProxy selectedTestProxy, @NotNull final Object sender, - final boolean requestFocus) { + final boolean requestFocus) { onSelectedHappend.set(); proxyRef.set(selectedTestProxy); focusRequestedRef.set(requestFocus); @@ -259,11 +259,213 @@ public class SMTestRunnerResultsFormTest extends BaseSMTRunnerTestCase { myResultsViewer.performUpdate(); final DefaultMutableTreeNode suite1Node = - (DefaultMutableTreeNode)myTreeModel.getChild(myTreeModel.getRoot(), 0); + (DefaultMutableTreeNode)myTreeModel.getChild(myTreeModel.getRoot(), 0); final DefaultMutableTreeNode suite2Node = - (DefaultMutableTreeNode)myTreeModel.getChild(suite1Node, 0); + (DefaultMutableTreeNode)myTreeModel.getChild(suite1Node, 0); assertTrue(myResultsViewer.getTreeView().isExpanded(new TreePath(suite1Node.getPath()))); assertFalse(myResultsViewer.getTreeView().isExpanded(new TreePath(suite2Node.getPath()))); } + + public void testCustomProgress_General() { + myResultsViewer.onCustomProgressTestsCategory("foo", 4); + + myResultsViewer.onTestStarted(createTestProxy("some_test1", myTestsRootNode)); + assertEquals(0, myResultsViewer.getTestsCurrentCount()); + myResultsViewer.onCustomProgressTestStarted(); + assertEquals(1, myResultsViewer.getTestsCurrentCount()); + + myResultsViewer.onTestStarted(createTestProxy("some_test2", myTestsRootNode)); + assertEquals(1, myResultsViewer.getTestsCurrentCount()); + myResultsViewer.onCustomProgressTestStarted(); + assertEquals(2, myResultsViewer.getTestsCurrentCount()); + } + + public void testCustomProgress_MixedMde() { + // enable custom mode + myResultsViewer.onCustomProgressTestsCategory("foo", 4); + + myResultsViewer.onTestStarted(createTestProxy("some_test1", myTestsRootNode)); + assertEquals(0, myResultsViewer.getTestsCurrentCount()); + myResultsViewer.onCustomProgressTestStarted(); + assertEquals(1, myResultsViewer.getTestsCurrentCount()); + + myResultsViewer.onTestStarted(createTestProxy("some_test2", myTestsRootNode)); + assertEquals(1, myResultsViewer.getTestsCurrentCount()); + myResultsViewer.onCustomProgressTestStarted(); + assertEquals(2, myResultsViewer.getTestsCurrentCount()); + + // disable custom mode + myResultsViewer.onCustomProgressTestsCategory(null, 0); + + assertEquals(2, myResultsViewer.getTestsCurrentCount()); + myResultsViewer.onCustomProgressTestStarted(); + assertEquals(2, myResultsViewer.getTestsCurrentCount()); + myResultsViewer.onTestStarted(createTestProxy("some_test1", myTestsRootNode)); + assertEquals(3, myResultsViewer.getTestsCurrentCount()); + + assertEquals(3, myResultsViewer.getTestsCurrentCount()); + myResultsViewer.onCustomProgressTestStarted(); + assertEquals(3, myResultsViewer.getTestsCurrentCount()); + myResultsViewer.onTestStarted(createTestProxy("some_test1", myTestsRootNode)); + assertEquals(4, myResultsViewer.getTestsCurrentCount()); + } + + public void testCustomProgress_Failure() { + myResultsViewer.onCustomProgressTestsCategory("foo", 4); + + final SMTestProxy test1 = createTestProxy("some_test1", myTestsRootNode); + myResultsViewer.onTestStarted(test1); + myResultsViewer.onCustomProgressTestStarted(); + + myResultsViewer.onTestFailed(test1); + assertEquals(0, myResultsViewer.getTestsFailuresCount()); + + myResultsViewer.onCustomProgressTestFailed(); + assertEquals(1, myResultsViewer.getTestsFailuresCount()); + } + + public void testCustomProgress_UnSetCount() { + myResultsViewer.onCustomProgressTestsCategory("foo", 0); + + assertEquals(0, myResultsViewer.getTestsTotal()); + + myResultsViewer.onCustomProgressTestStarted(); + assertEquals(0, myResultsViewer.getTestsTotal()); + + myResultsViewer.onCustomProgressTestStarted(); + assertEquals(0, myResultsViewer.getTestsTotal()); + + // count will be updated only on tests finished if wasn't set + myResultsViewer.onTestingFinished(myTestsRootNode); + assertEquals(2, myResultsViewer.getTestsTotal()); + } + + public void testCustomProgress_IncreaseCount() { + myResultsViewer.onCustomProgressTestsCategory("foo", 1); + + assertEquals(1, myResultsViewer.getTestsTotal()); + + myResultsViewer.onCustomProgressTestStarted(); + assertEquals(1, myResultsViewer.getTestsTotal()); + + myResultsViewer.onCustomProgressTestStarted(); + assertEquals(2, myResultsViewer.getTestsTotal()); + } + + public void testCustomProgress_IncreaseCount_MixedMode() { + // custom mode + myResultsViewer.onCustomProgressTestsCategory("foo", 1); + + assertEquals(1, myResultsViewer.getTestsTotal()); + + myResultsViewer.onCustomProgressTestStarted(); + assertEquals(1, myResultsViewer.getTestsTotal()); + + myResultsViewer.onCustomProgressTestStarted(); + assertEquals(2, myResultsViewer.getTestsTotal()); + + // disable custom mode + myResultsViewer.onCustomProgressTestsCategory(null, 0); + assertEquals(2, myResultsViewer.getTestsTotal()); + + myResultsViewer.onTestsCountInSuite(1); + assertEquals(3, myResultsViewer.getTestsTotal()); + + myResultsViewer.onTestStarted(createTestProxy("some_test1", myTestsRootNode)); + assertEquals(3, myResultsViewer.getTestsTotal()); + + myResultsViewer.onTestStarted(createTestProxy("some_test2", myTestsRootNode)); + assertEquals(4, myResultsViewer.getTestsTotal()); + } + + //TODO categories - mized + + public void testCustomProgress_MentionedCategories_CategoryWithoutName() { + // enable custom mode + assertTrue(myResultsViewer.getMentionedCategories().isEmpty()); + + myResultsViewer.onCustomProgressTestsCategory("foo", 4); + + assertTrue(myResultsViewer.getMentionedCategories().isEmpty()); + } + + public void testCustomProgress_MentionedCategories_DefaultCategory() { + // enable custom mode + assertTrue(myResultsViewer.getMentionedCategories().isEmpty()); + + myResultsViewer.onCustomProgressTestStarted(); + + assertTrue(myResultsViewer.getMentionedCategories().isEmpty()); + } + + public void testCustomProgress_MentionedCategories_OneCustomCategory() { + // enable custom mode + myResultsViewer.onCustomProgressTestsCategory("Foo", 4); + assertTrue(myResultsViewer.getMentionedCategories().isEmpty()); + + myResultsViewer.onTestStarted(createTestProxy("some_test1", myTestsRootNode)); + assertTrue(myResultsViewer.getMentionedCategories().isEmpty()); + + myResultsViewer.onCustomProgressTestStarted(); + assertSameElements(myResultsViewer.getMentionedCategories(), "Foo"); + + // disable custom mode + myResultsViewer.onCustomProgressTestsCategory(null, 0); + assertSameElements(myResultsViewer.getMentionedCategories(), "Foo"); + } + + public void testCustomProgress_MentionedCategories_SeveralCategories() { + // enable custom mode + myResultsViewer.onCustomProgressTestsCategory("Foo", 4); + assertTrue(myResultsViewer.getMentionedCategories().isEmpty()); + + myResultsViewer.onTestStarted(createTestProxy("some_test1", myTestsRootNode)); + assertTrue(myResultsViewer.getMentionedCategories().isEmpty()); + + myResultsViewer.onCustomProgressTestStarted(); + assertSameElements(myResultsViewer.getMentionedCategories(), "Foo"); + + // disable custom mode + myResultsViewer.onCustomProgressTestsCategory(null, 0); + + myResultsViewer.onCustomProgressTestStarted(); + assertSameElements(myResultsViewer.getMentionedCategories(), "Foo"); + + myResultsViewer.onTestStarted(createTestProxy("some_test2", myTestsRootNode)); + assertSameElements(myResultsViewer.getMentionedCategories(), "Foo", TestsPresentationUtil.DEFAULT_TESTS_CATEGORY); + } + + public void testCustomProgress_MentionedCategories() { + // enable custom mode + assertTrue(myResultsViewer.getMentionedCategories().isEmpty()); + + myResultsViewer.onCustomProgressTestsCategory("foo", 4); + + myResultsViewer.onTestStarted(createTestProxy("some_test1", myTestsRootNode)); + assertEquals(0, myResultsViewer.getTestsCurrentCount()); + myResultsViewer.onCustomProgressTestStarted(); + assertEquals(1, myResultsViewer.getTestsCurrentCount()); + + myResultsViewer.onTestStarted(createTestProxy("some_test2", myTestsRootNode)); + assertEquals(1, myResultsViewer.getTestsCurrentCount()); + myResultsViewer.onCustomProgressTestStarted(); + assertEquals(2, myResultsViewer.getTestsCurrentCount()); + + // disable custom mode + myResultsViewer.onCustomProgressTestsCategory(null, 0); + + assertEquals(2, myResultsViewer.getTestsCurrentCount()); + myResultsViewer.onCustomProgressTestStarted(); + assertEquals(2, myResultsViewer.getTestsCurrentCount()); + myResultsViewer.onTestStarted(createTestProxy("some_test1", myTestsRootNode)); + assertEquals(3, myResultsViewer.getTestsCurrentCount()); + + assertEquals(3, myResultsViewer.getTestsCurrentCount()); + myResultsViewer.onCustomProgressTestStarted(); + assertEquals(3, myResultsViewer.getTestsCurrentCount()); + myResultsViewer.onTestStarted(createTestProxy("some_test1", myTestsRootNode)); + assertEquals(4, myResultsViewer.getTestsCurrentCount()); + } + } diff --git a/platform/smRunner/testSrc/com/intellij/execution/testframework/sm/runner/ui/TestsPresentationUtilTest.java b/platform/smRunner/testSrc/com/intellij/execution/testframework/sm/runner/ui/TestsPresentationUtilTest.java index ea02b3f2089e..cf990a42d149 100644 --- a/platform/smRunner/testSrc/com/intellij/execution/testframework/sm/runner/ui/TestsPresentationUtilTest.java +++ b/platform/smRunner/testSrc/com/intellij/execution/testframework/sm/runner/ui/TestsPresentationUtilTest.java @@ -7,6 +7,7 @@ import com.intellij.execution.testframework.sm.runner.SMTestProxy; import com.intellij.execution.testframework.sm.UITestUtil; import com.intellij.execution.testframework.ui.TestsProgressAnimator; import com.intellij.ui.SimpleTextAttributes; +import com.intellij.util.containers.HashSet; import org.jetbrains.annotations.Nls; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -31,24 +32,55 @@ public class TestsPresentationUtilTest extends BaseSMTRunnerTestCase { public void testProgressText() { assertEquals("Running: 10 of 1 Failed: 1 ", - TestsPresentationUtil.getProgressStatus_Text(0, 0, 1, 10, 1)); + TestsPresentationUtil.getProgressStatus_Text(0, 0, 1, 10, 1, null)); assertEquals("Running: 10 of 1 ", - TestsPresentationUtil.getProgressStatus_Text(0, 0, 1, 10, 0)); + TestsPresentationUtil.getProgressStatus_Text(0, 0, 1, 10, 0, null)); //here number format is platform-dependent assertEquals("Done: 10 of 1 (0 s) ", - TestsPresentationUtil.getProgressStatus_Text(5, 5, 1, 10, 0)); + TestsPresentationUtil.getProgressStatus_Text(5, 5, 1, 10, 0, null)); } public void testProgressText_UnsetTotal() { assertEquals("Running: 0 of <...> ", - TestsPresentationUtil.getProgressStatus_Text(0, 0, 0, 0, 0)); + TestsPresentationUtil.getProgressStatus_Text(0, 0, 0, 0, 0, null)); assertEquals("Running: 1 of <...> Failed: 1 ", - TestsPresentationUtil.getProgressStatus_Text(0, 0, 0, 1, 1)); + TestsPresentationUtil.getProgressStatus_Text(0, 0, 0, 1, 1, null)); assertEquals("Running: 10 of <...> Failed: 1 ", - TestsPresentationUtil.getProgressStatus_Text(0, 0, 0, 10, 1)); + TestsPresentationUtil.getProgressStatus_Text(0, 0, 0, 10, 1, null)); //here number format is platform-dependent assertEquals("Done: 10 of <...> Failed: 1 (5 ms) ", - TestsPresentationUtil.getProgressStatus_Text(0, 5, 0, 10, 1)); + TestsPresentationUtil.getProgressStatus_Text(0, 5, 0, 10, 1, null)); + } + + public void testProgressText_Category() { + assertEquals("Running: 0 of <...> ", + TestsPresentationUtil.getProgressStatus_Text(0, 0, 0, 0, 0, new HashSet())); + + final HashSet category = new HashSet(); + + category.clear(); + category.add("Scenarios"); + assertEquals("Running: Scenarios 0 of <...> ", + TestsPresentationUtil.getProgressStatus_Text(0, 0, 0, 0, 0, category)); + + category.clear(); + category.add("Scenarios"); + category.add(TestsPresentationUtil.DEFAULT_TESTS_CATEGORY); + assertEquals("Running: Scenarios, tests 0 of <...> ", + TestsPresentationUtil.getProgressStatus_Text(0, 0, 0, 0, 0, category)); + + category.clear(); + category.add("Cucumbers"); + category.add("Tomatos"); + category.add(TestsPresentationUtil.DEFAULT_TESTS_CATEGORY); + assertEquals("Running: Tests, tomatos, cucumbers 0 of <...> ", + TestsPresentationUtil.getProgressStatus_Text(0, 0, 0, 0, 0, category)); + + category.clear(); + category.add(TestsPresentationUtil.DEFAULT_TESTS_CATEGORY); + assertEquals("Running: 0 of <...> ", + TestsPresentationUtil.getProgressStatus_Text(0, 0, 0, 0, 0, category)); + } public void testFormatTestProxyTest_NewTest() {