From 857ef619dcaf1fd58e2bc43e0c50be77cfd24800 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Wed, 13 Dec 2017 16:12:48 +0100 Subject: [PATCH] [tests] simplifies and speedups "recent tests" tests --- .../testIntergration/RecentTestsOrderTest.kt | 167 +++++------------- .../testIntergration/RecentTestsTest.kt | 159 ++++++----------- .../testIntergration/RecentTestsTestCase.kt | 36 ++++ 3 files changed, 133 insertions(+), 229 deletions(-) create mode 100644 java/java-tests/testSrc/com/intellij/testIntergration/RecentTestsTestCase.kt diff --git a/java/java-tests/testSrc/com/intellij/testIntergration/RecentTestsOrderTest.kt b/java/java-tests/testSrc/com/intellij/testIntergration/RecentTestsOrderTest.kt index 66048cf185e1..3f92620c80ef 100644 --- a/java/java-tests/testSrc/com/intellij/testIntergration/RecentTestsOrderTest.kt +++ b/java/java-tests/testSrc/com/intellij/testIntergration/RecentTestsOrderTest.kt @@ -1,161 +1,86 @@ /* - * Copyright 2000-2016 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. + * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. */ package com.intellij.testIntergration -import com.intellij.execution.RunnerAndConfigurationSettings -import com.intellij.execution.testframework.sm.runner.states.TestStateInfo.Magnitude.FAILED_INDEX -import com.intellij.execution.testframework.sm.runner.states.TestStateInfo.Magnitude.PASSED_INDEX -import com.intellij.testFramework.LightIdeaTestCase -import com.intellij.testIntegration.RecentTestsData -import com.intellij.testIntegration.SingleTestEntry -import com.intellij.testIntegration.SuiteEntry import org.assertj.core.api.Assertions.assertThat +import org.junit.Test import java.util.* -class RecentTestsOrderTest: LightIdeaTestCase() { +class RecentTestsOrderTest : RecentTestsTestCase() { + @Test fun `test run configuration with one suite shows only suite`() { + addPassedTest("MySingleTest.test1", now) + addSuite("MySingleTest", now) - lateinit var data: RecentTestsData - lateinit var allTests: RunnerAndConfigurationSettings - lateinit var now: Date - - override fun setUp() { - super.setUp() - data = RecentTestsData() - allTests = mockConfiguration("all tests", "JUnit.all tests") - now = Date() - } - - fun addPassedSuite(suiteUrl: String, date: Date = Date(), runConfiguration: RunnerAndConfigurationSettings = allTests) { - val suite = SuiteEntry(suiteUrl, date, runConfiguration) - data.addSuite(suite) - } - - fun addFailedSuite(suiteUrl: String, date: Date = Date(), runConfiguration: RunnerAndConfigurationSettings = allTests) { - val suite = SuiteEntry(suiteUrl, date, runConfiguration) - data.addSuite(suite) - } - - fun addPassedTest(testUrl: String, date: Date = Date(), runConfiguration: RunnerAndConfigurationSettings = allTests) { - val test = SingleTestEntry(testUrl, date, runConfiguration, PASSED_INDEX) - data.addTest(test) - } - - fun addFailedTest(testUrl: String, date: Date = Date(), runConfiguration: RunnerAndConfigurationSettings = allTests) { - val test = SingleTestEntry(testUrl, date, runConfiguration, FAILED_INDEX) - data.addTest(test) - } - - fun `test run configuration with one suite shows only suite`() { - val suite = "MySingleTest".suite() - val test1 = "MySingleTest.test1".test() - - data.addTest(SingleTestEntry(test1, now, allTests, PASSED_INDEX)) - data.addSuite(SuiteEntry(suite, now, allTests)) - - val testsToShow = data.getTestsToShow() + val testsToShow = getTestsToShow() assertThat(testsToShow).hasSize(1) assertThat(testsToShow[0].presentation).isEqualTo("all tests") } - - fun `test run configuration with multiple suites shows run configuration name`() { - val suite1 = "MyFirstTest".suite() - val test1 = "MyFirstTest.test1".test() - - val suite2 = "MySecondTest".suite() - val test2 = "MySecondTest.test1".test() - - addPassedSuite(suite1, now) - addPassedTest(test1, now) - - addPassedSuite(suite2) - addPassedTest(test2) - val tests = data.getTestsToShow() + @Test fun `test run configuration with multiple suites shows run configuration name`() { + addSuite("MyFirstTest", now) + addPassedTest("MyFirstTest.test1", now) + + addSuite("MySecondTest", Date()) + addPassedTest("MySecondTest.test1", Date()) + + val tests = getTestsToShow() assertThat(tests).hasSize(1) assertThat(tests[0].presentation).isEqualTo("all tests") } - - fun `test show failed suite in test`() { - val suite = "SingleTest".suite() - val test = "SingleTest.test".test() - - addPassedSuite(suite) - addFailedTest(test) - - val tests = data.getTestsToShow() + + @Test fun `test show failed suite in test`() { + addSuite("SingleTest", Date()) + addFailedTest("SingleTest.test", Date()) + + val tests = getTestsToShow() assertThat(tests).hasSize(1) - - assertThat(tests[0].presentation).isEqualTo("SingleTest.test") - assertThat(tests[0].failed).isEqualTo(true) - } - - fun `test show failed suite and test in run configuration`() { - val suite = "SingleTest".suite() - val test = "SingleTest.test".test() - val test2 = "SingleTest.test2".test() - - addPassedSuite(suite) - addFailedTest(test) - addPassedTest(test2) - - addPassedSuite("PassedSuite".suite()) - - val tests = data.getTestsToShow() - assertThat(tests).hasSize(1) - assertThat(tests[0].presentation).isEqualTo("SingleTest.test") assertThat(tests[0].failed).isEqualTo(true) } - fun `test single test run doesn't override suite status`() { + @Test fun `test show failed suite and test in run configuration`() { + addSuite("SingleTest", Date()) + addFailedTest("SingleTest.test", Date()) + addPassedTest("SingleTest.test2", Date()) + addSuite("PassedSuite", Date()) + + val tests = getTestsToShow() + assertThat(tests).hasSize(1) + assertThat(tests[0].presentation).isEqualTo("SingleTest.test") + assertThat(tests[0].failed).isEqualTo(true) + } + + @Test fun `test single test run doesn't override suite status`() { val singleTestConfig = mockConfiguration("single test", "Junit.single test") - val newNow = Date(now.time + 100000) //previous all suite run - addFailedTest("Test.testFailed".test(), now, allTests) + addFailedTest("Test.testFailed", now) //current single test run - addPassedSuite("Test".suite(), newNow, singleTestConfig) - addPassedTest("Test.testOK".test(), newNow, singleTestConfig) - - val tests = data.getTestsToShow() - assertThat(tests).hasSize(2) + addSuite("Test", newNow, singleTestConfig) + addPassedTest("Test.testOK", newNow, singleTestConfig) + val tests = getTestsToShow() + assertThat(tests).hasSize(2) assertThat(tests[0].presentation).isEqualTo("single test") assertThat(tests[1].presentation).isEqualTo("Test.testFailed") } - - fun `test single test run doesn't override suite status, independent from registering order`() { + @Test fun `test single test run doesn't override suite status, independent from registering order`() { val singleTestConfig = mockConfiguration("single test", "Junit.single test") - val newNow = Date(now.time + 100000) - + //previous all suite run - addPassedTest("Test.testOK".test(), now, allTests) - + addPassedTest("Test.testOK", now) + //current single test run - addFailedSuite("Test".suite(), newNow, singleTestConfig) - addFailedTest("Test.testFailed".test(), newNow, singleTestConfig) + addSuite("Test", newNow, singleTestConfig) + addFailedTest("Test.testFailed", newNow, singleTestConfig) - val tests = data.getTestsToShow() + val tests = getTestsToShow() assertThat(tests).hasSize(1) - assertThat(tests[0].presentation).isEqualTo("Test.testFailed") } - } \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/testIntergration/RecentTestsTest.kt b/java/java-tests/testSrc/com/intellij/testIntergration/RecentTestsTest.kt index 0ab2c5966a41..720fed2bb9a2 100644 --- a/java/java-tests/testSrc/com/intellij/testIntergration/RecentTestsTest.kt +++ b/java/java-tests/testSrc/com/intellij/testIntergration/RecentTestsTest.kt @@ -1,144 +1,87 @@ /* - * 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. + * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. */ package com.intellij.testIntergration -import com.intellij.execution.RunnerAndConfigurationSettings -import com.intellij.execution.testframework.sm.runner.states.TestStateInfo.Magnitude.FAILED_INDEX -import com.intellij.execution.testframework.sm.runner.states.TestStateInfo.Magnitude.PASSED_INDEX -import com.intellij.testFramework.LightIdeaTestCase -import com.intellij.testIntegration.* +import com.intellij.testIntegration.RecentTestsPopupEntry +import com.intellij.testIntegration.RunConfigurationEntry +import com.intellij.testIntegration.SuiteEntry +import com.intellij.testIntegration.TestConfigurationCollector import org.assertj.core.api.Assertions.assertThat -import org.mockito.Mockito.`when` -import org.mockito.Mockito.mock -import java.util.* +import org.junit.Test -fun String.suite() = "java:suite://$this" -fun String.test() = "java:test://$this" +class RecentTestsStepTest : RecentTestsTestCase() { + @Test fun `test all tests passed`() { + addPassedTest("Test.textXXX", now) + addSuite("Test", now) + addSuite("JFSDTest", now) + addPassedTest("Test.textYYY", now) + addPassedTest("JFSDTest.testItMakesMeSadToFixIt", now) + addPassedTest("Test.textZZZ", now) + addPassedTest("Test.textQQQ", now) + addPassedTest("JFSDTest.testUnconditionalAlignmentErroneous", now) -fun mockConfiguration(name: String, uniqueID: String): RunnerAndConfigurationSettings { - val settings = mock(RunnerAndConfigurationSettings::class.java) - `when`(settings.uniqueID).thenAnswer { uniqueID } - `when`(settings.name).thenAnswer { name } - return settings -} - -class RecentTestsStepTest: LightIdeaTestCase() { - - lateinit var data: RecentTestsData - lateinit var allTests: RunnerAndConfigurationSettings - lateinit var now: Date - - override fun setUp() { - super.setUp() - data = RecentTestsData() - allTests = mockConfiguration("all tests", "JUnit.all tests") - now = Date() - } - - fun `test all tests passed`() { - - data.addTest(SingleTestEntry("Test.textXXX".test(), now, allTests, PASSED_INDEX)) - - - data.addSuite(SuiteEntry("Test".suite(), now, allTests)) - - data.addSuite(SuiteEntry("JFSDTest".suite(), now, allTests)) - - data.addTest(SingleTestEntry("Test.textYYY".test(), now, allTests, PASSED_INDEX)) - data.addTest(SingleTestEntry("JFSDTest.testItMakesMeSadToFixIt".test(), now, allTests, PASSED_INDEX)) - data.addTest(SingleTestEntry("Test.textZZZ".test(), now, allTests, PASSED_INDEX)) - data.addTest(SingleTestEntry("Test.textQQQ".test(), now, allTests, PASSED_INDEX)) - data.addTest(SingleTestEntry("JFSDTest.testUnconditionalAlignmentErrorneous".test(), now, allTests, PASSED_INDEX)) - - val tests = data.getTestsToShow() + val tests = getTestsToShow() assertThat(tests).hasSize(1) assertThat(tests[0].presentation).isEqualTo("all tests") } + @Test fun `test if one failed in run configuration show failed suite`() { + addSuite("JFSDTest", now) + addSuite("Test", now) + addFailedTest("JFSDTest.testItMakesMeSadToFixIt", now) + addPassedTest("JFSDTest.testUnconditionalAlignmentErroneous", now) + addPassedTest("Test.textXXX", now) - fun `test if one failed in run configuration show failed suite`() { - data.addSuite(SuiteEntry("JFSDTest".suite(), now, allTests)) - data.addSuite(SuiteEntry("Test".suite(), now, allTests)) - - data.addTest(SingleTestEntry("JFSDTest.testItMakesMeSadToFixIt".test(), now, allTests, FAILED_INDEX)) - data.addTest(SingleTestEntry("JFSDTest.testUnconditionalAlignmentErrorneous".test(), now, allTests, PASSED_INDEX)) - - data.addTest(SingleTestEntry("Test.textXXX".test(), now, allTests, PASSED_INDEX)) - - val tests = data.getTestsToShow() - + val tests = getTestsToShow() assertThat(tests).hasSize(1) - assertThat(tests[0].presentation).isEqualTo("JFSDTest.testItMakesMeSadToFixIt") assertThat(tests[0].failed).isEqualTo(true) } - - - fun `test if configuration with single test show failed test`() { - data.addSuite(SuiteEntry("JFSDTest".suite(), now, allTests)) - data.addTest(SingleTestEntry("JFSDTest.testItMakesMeSadToFixIt".test(), now, allTests, FAILED_INDEX)) - data.addTest(SingleTestEntry("JFSDTest.testUnconditionalAlignmentErrorneous".test(), now, allTests, PASSED_INDEX)) - - val tests = data.getTestsToShow() + + @Test fun `test if configuration with single test show failed test`() { + addSuite("JFSDTest", now) + addFailedTest("JFSDTest.testItMakesMeSadToFixIt", now) + addPassedTest("JFSDTest.testUnconditionalAlignmentErroneous", now) + + val tests = getTestsToShow() assertThat(tests).hasSize(1) assertThat(tests[0].presentation).isEqualTo("JFSDTest.testItMakesMeSadToFixIt") } - - fun `test show test without suite`() { - data.addTest(SingleTestEntry("Test.sssss".test(), now, allTests, FAILED_INDEX)) - val testsToShow = data.getTestsToShow() + @Test fun `test show test without suite`() { + addFailedTest("Test.someTest", now) + val testsToShow = getTestsToShow() assertThat(testsToShow).hasSize(1) } + @Test fun `test additional entries`() { + addSuite("Test2", now) + addSuite("Test", now) + addFailedTest("Test.sss", now) - fun `test additional entries`() { - data.addSuite(SuiteEntry("Test2".suite(), now, allTests)) - data.addSuite(SuiteEntry("Test".suite(), now, allTests)) - data.addTest(SingleTestEntry("Test.sss".test(), now, allTests, FAILED_INDEX)) - - val tests = data.getTestsToShow() + val tests = getTestsToShow() assertThat(tests).hasSize(1) - - val failedTest = tests[0] - - val collector = TestConfigurationCollector() - failedTest.accept(collector) - val configs = collector.getEnclosingConfigurations() - + val configs = getConfigs(tests[0]) assertThat(configs).hasSize(2) assertThat(configs[0]).isInstanceOf(SuiteEntry::class.java) assertThat(configs[1]).isInstanceOf(RunConfigurationEntry::class.java) } - fun `test if configuration consists of single test show only configuration`() { - data.addSuite(SuiteEntry("Test".suite(), now, allTests)) - data.addTest(SingleTestEntry("Test.sss".test(), now, allTests, FAILED_INDEX)) - val tests = data.getTestsToShow() - + @Test fun `test if configuration consists of single test show only configuration`() { + addSuite("Test", now) + addFailedTest("Test.sss", now) + + val tests = getTestsToShow() assertThat(tests).hasSize(1) - - val collector = TestConfigurationCollector() - tests[0].accept(collector) - val configs = collector.getEnclosingConfigurations() - + val configs = getConfigs(tests[0]) assertThat(configs).hasSize(1) assertThat(configs[0]).isInstanceOf(RunConfigurationEntry::class.java) } - - + private fun getConfigs(test: RecentTestsPopupEntry): List { + val collector = TestConfigurationCollector() + test.accept(collector) + return collector.getEnclosingConfigurations() + } } \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/testIntergration/RecentTestsTestCase.kt b/java/java-tests/testSrc/com/intellij/testIntergration/RecentTestsTestCase.kt new file mode 100644 index 000000000000..8595004e14a6 --- /dev/null +++ b/java/java-tests/testSrc/com/intellij/testIntergration/RecentTestsTestCase.kt @@ -0,0 +1,36 @@ +/* + * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. + */ +package com.intellij.testIntergration + +import com.intellij.execution.RunnerAndConfigurationSettings +import com.intellij.execution.testframework.sm.runner.states.TestStateInfo +import com.intellij.testIntegration.RecentTestsData +import com.intellij.testIntegration.SingleTestEntry +import com.intellij.testIntegration.SuiteEntry +import org.mockito.Mockito +import java.util.* + +abstract class RecentTestsTestCase { + private val data = RecentTestsData() + private val allTests: RunnerAndConfigurationSettings = mockConfiguration("all tests", "JUnit.all tests") + protected val now = Date() + + protected fun mockConfiguration(name: String, uniqueID: String): RunnerAndConfigurationSettings { + val settings = Mockito.mock(RunnerAndConfigurationSettings::class.java) + Mockito.`when`(settings.uniqueID).thenAnswer { uniqueID } + Mockito.`when`(settings.name).thenAnswer { name } + return settings + } + + protected fun addSuite(suiteName: String, date: Date, runConfiguration: RunnerAndConfigurationSettings = allTests) = + data.addSuite(SuiteEntry("java:suite://$suiteName", date, runConfiguration)) + + protected fun addPassedTest(testName: String, date: Date, runConfiguration: RunnerAndConfigurationSettings = allTests) = + data.addTest(SingleTestEntry("java:test://$testName", date, runConfiguration, TestStateInfo.Magnitude.PASSED_INDEX)) + + protected fun addFailedTest(testName: String, date: Date, runConfiguration: RunnerAndConfigurationSettings = allTests) = + data.addTest(SingleTestEntry("java:test://$testName", date, runConfiguration, TestStateInfo.Magnitude.FAILED_INDEX)) + + protected fun getTestsToShow() = data.getTestsToShow() +} \ No newline at end of file