From b3a49ff090ab7823822f5ed37a8ada11f6b6e4fc Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Wed, 24 Jun 2015 16:12:21 +0300 Subject: [PATCH] tests view: hide ignored/hide passed filters combinations (IDEA-121329) --- .../testframework/sm/runner/SMTestProxy.java | 14 +-- .../sm/runner/ui/SMTRunnerFiltersTest.java | 105 ++++++++++++++++++ .../testframework/AbstractTestProxy.java | 2 + .../execution/testframework/Filter.java | 7 ++ .../actions/TestFrameworkActions.java | 9 +- .../intellij/execution/junit2/TestProxy.java | 5 + .../testng/model/TestProxy.java | 5 + 7 files changed, 139 insertions(+), 8 deletions(-) create mode 100644 platform/smRunner/testSrc/com/intellij/execution/testframework/sm/runner/ui/SMTRunnerFiltersTest.java diff --git a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/SMTestProxy.java b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/SMTestProxy.java index e7ca2378917c..e4c553cbc76a 100644 --- a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/SMTestProxy.java +++ b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/SMTestProxy.java @@ -182,11 +182,7 @@ public class SMTestProxy extends AbstractTestProxy { } @Override - public boolean isInterrupted() { - return myState.wasTerminated(); - } - - boolean hasPassedTests() { + public boolean hasPassedTests() { if (myHasPassedTestsCached) { return myHasPassedTests; } @@ -197,6 +193,11 @@ public class SMTestProxy extends AbstractTestProxy { myHasPassedTestsCached = true; } return hasPassedTests; + + } + @Override + public boolean isInterrupted() { + return myState.wasTerminated(); } private boolean calcPassedTests() { @@ -213,8 +214,7 @@ public class SMTestProxy extends AbstractTestProxy { @Override public boolean isIgnored() { - return !hasPassedTests() && - myState.getMagnitude() == TestStateInfo.Magnitude.IGNORED_INDEX; + return myState.getMagnitude() == TestStateInfo.Magnitude.IGNORED_INDEX; } public boolean isPassed() { diff --git a/platform/smRunner/testSrc/com/intellij/execution/testframework/sm/runner/ui/SMTRunnerFiltersTest.java b/platform/smRunner/testSrc/com/intellij/execution/testframework/sm/runner/ui/SMTRunnerFiltersTest.java new file mode 100644 index 000000000000..9a853be05875 --- /dev/null +++ b/platform/smRunner/testSrc/com/intellij/execution/testframework/sm/runner/ui/SMTRunnerFiltersTest.java @@ -0,0 +1,105 @@ +/* + * Copyright 2000-2015 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.execution.testframework.sm.runner.ui; + +import com.intellij.execution.testframework.TestConsoleProperties; +import com.intellij.execution.testframework.sm.runner.BaseSMTRunnerTestCase; +import com.intellij.execution.testframework.sm.runner.SMTRunnerTreeStructure; +import com.intellij.execution.testframework.sm.runner.SMTestProxy; +import com.intellij.openapi.util.Disposer; + +import javax.swing.*; + +public class SMTRunnerFiltersTest extends BaseSMTRunnerTestCase { + private MockTestResultsViewer myResultsViewer; + private TestConsoleProperties myProperties; + private SMTestRunnerResultsForm myResultsForm; + + @Override + protected void setUp() throws Exception { + super.setUp(); + + myProperties = createConsoleProperties(); + myResultsViewer = new MockTestResultsViewer(myProperties, mySuite); + + TestConsoleProperties.HIDE_PASSED_TESTS.set(myProperties, false); + TestConsoleProperties.HIDE_IGNORED_TEST.set(myProperties, false); + myResultsForm = new SMTestRunnerResultsForm(new JLabel(), myProperties); + Disposer.register(myResultsForm, myProperties); + myResultsForm.initUI(); + + //setup suites tree + mySuite.setStarted(); + + final SMTestProxy testsSuite = createSuiteProxy("my suite", mySuite); + testsSuite.setStarted(); + + // passed test + final SMTestProxy testPassed1 = createTestProxy("testPassed1", testsSuite); + testPassed1.setStarted(); + testPassed1.setFinished(); + + //ignored test + final SMTestProxy testIgnored1 = createTestProxy("testIgnored1", testsSuite); + testIgnored1.setStarted(); + testIgnored1.setTestIgnored("", ""); + testsSuite.setFinished(); + mySuite.setFinished(); + } + + @Override + protected void tearDown() throws Exception { + Disposer.dispose(myResultsViewer); + Disposer.dispose(myResultsForm); + super.tearDown(); + } + + public void testShowPassedShowIgnored() { + final SMTRunnerTreeStructure treeStructure = myResultsForm.getTreeBuilder().getSMRunnerTreeStructure(); + final Object[] suites = treeStructure.getChildElements(mySuite); + assertTrue(suites.length == 1); + final Object[] tests = treeStructure.getChildElements(suites[0]); + assertTrue(tests.length == 2); + } + + public void testShowPassedHideIgnored() { + TestConsoleProperties.HIDE_IGNORED_TEST.set(myProperties, true); + final SMTRunnerTreeStructure treeStructure = myResultsForm.getTreeBuilder().getSMRunnerTreeStructure(); + final Object[] suites = treeStructure.getChildElements(mySuite); + assertTrue(suites.length == 1); + final Object[] tests = treeStructure.getChildElements(suites[0]); + assertTrue(tests.length == 1); + assertTrue(tests[0] instanceof SMTestProxy && "testPassed1".equals(((SMTestProxy)tests[0]).getName())); + } + + public void testShowIgnoredHidePassed() { + TestConsoleProperties.HIDE_PASSED_TESTS.set(myProperties, true); + final SMTRunnerTreeStructure treeStructure = myResultsForm.getTreeBuilder().getSMRunnerTreeStructure(); + final Object[] suites = treeStructure.getChildElements(mySuite); + assertTrue(suites.length == 1); + final Object[] tests = treeStructure.getChildElements(suites[0]); + assertTrue(tests.length == 1); + assertTrue(tests[0] instanceof SMTestProxy && "testIgnored1".equals(((SMTestProxy)tests[0]).getName())); + } + + public void testHidePassedHideIgnored() { + TestConsoleProperties.HIDE_PASSED_TESTS.set(myProperties, true); + TestConsoleProperties.HIDE_IGNORED_TEST.set(myProperties, true); + final SMTRunnerTreeStructure treeStructure = myResultsForm.getTreeBuilder().getSMRunnerTreeStructure(); + final Object[] suites = treeStructure.getChildElements(mySuite); + assertTrue(suites.length == 0); + } +} diff --git a/platform/testRunner/src/com/intellij/execution/testframework/AbstractTestProxy.java b/platform/testRunner/src/com/intellij/execution/testframework/AbstractTestProxy.java index 85f012805d1d..22afef01964f 100644 --- a/platform/testRunner/src/com/intellij/execution/testframework/AbstractTestProxy.java +++ b/platform/testRunner/src/com/intellij/execution/testframework/AbstractTestProxy.java @@ -48,6 +48,8 @@ public abstract class AbstractTestProxy extends CompositePrintable { public abstract boolean isInterrupted(); + public abstract boolean hasPassedTests(); + public abstract boolean isIgnored(); public abstract boolean isPassed(); diff --git a/platform/testRunner/src/com/intellij/execution/testframework/Filter.java b/platform/testRunner/src/com/intellij/execution/testframework/Filter.java index 8dd6363c5940..d6f7cafe997e 100644 --- a/platform/testRunner/src/com/intellij/execution/testframework/Filter.java +++ b/platform/testRunner/src/com/intellij/execution/testframework/Filter.java @@ -95,6 +95,13 @@ public abstract class Filter { } }; + public static final Filter HAS_PASSED = new Filter() { + @Override + public boolean shouldAccept(final AbstractTestProxy test) { + return test.hasPassedTests(); + } + }; + public static final Filter FAILED_OR_INTERRUPTED = new Filter() { @Override public boolean shouldAccept(final AbstractTestProxy test) { diff --git a/platform/testRunner/src/com/intellij/execution/testframework/actions/TestFrameworkActions.java b/platform/testRunner/src/com/intellij/execution/testframework/actions/TestFrameworkActions.java index 1c67d89f07b1..ebde565df5dc 100644 --- a/platform/testRunner/src/com/intellij/execution/testframework/actions/TestFrameworkActions.java +++ b/platform/testRunner/src/com/intellij/execution/testframework/actions/TestFrameworkActions.java @@ -51,7 +51,14 @@ public class TestFrameworkActions { final Filter hidePassedFilter = shouldFilterPassed ? Filter.NOT_PASSED.or(Filter.DEFECT) : Filter.NO_FILTER; final boolean shouldFilterIgnored = TestConsoleProperties.HIDE_IGNORED_TEST.value(properties); - final Filter hideIgnoredFilter = shouldFilterIgnored ? Filter.IGNORED.not() : Filter.NO_FILTER; + final Filter hideIgnoredFilter; + if (shouldFilterIgnored) { + final Filter ignoredFilter = Filter.IGNORED.not(); + hideIgnoredFilter = !shouldFilterPassed ? ignoredFilter.or(Filter.HAS_PASSED) : ignoredFilter; + } + else { + hideIgnoredFilter = Filter.NO_FILTER; + } return hidePassedFilter.and(hideIgnoredFilter); } diff --git a/plugins/junit/src/com/intellij/execution/junit2/TestProxy.java b/plugins/junit/src/com/intellij/execution/junit2/TestProxy.java index f7a6ab69f390..31e17aa5694d 100644 --- a/plugins/junit/src/com/intellij/execution/junit2/TestProxy.java +++ b/plugins/junit/src/com/intellij/execution/junit2/TestProxy.java @@ -172,6 +172,11 @@ public class TestProxy extends AbstractTestProxy { return getMagnitude() == PoolOfTestStates.TERMINATED_INDEX; } + @Override + public boolean hasPassedTests() { + return isPassed(); + } + @Override public boolean isIgnored() { return myState instanceof IgnoredState; diff --git a/plugins/testng/src/com/theoryinpractice/testng/model/TestProxy.java b/plugins/testng/src/com/theoryinpractice/testng/model/TestProxy.java index 119d5a46aa81..c7a1e8c27ecc 100644 --- a/plugins/testng/src/com/theoryinpractice/testng/model/TestProxy.java +++ b/plugins/testng/src/com/theoryinpractice/testng/model/TestProxy.java @@ -238,6 +238,11 @@ public class TestProxy extends AbstractTestProxy { return !isInProgress() && inProgress; } + @Override + public boolean hasPassedTests() { + return isPassed(); + } + @Override public boolean isIgnored() { return resultMessage != null && MessageHelper.SKIPPED_TEST == resultMessage.getResult();