[Recent Tests] attach unmatched tests to it's suites, even if they were executed from different run configurations

This commit is contained in:
Yaroslav Lepenkin
2016-06-15 18:23:40 +03:00
parent a1747521c5
commit 47cef86c7c
4 changed files with 73 additions and 13 deletions
@@ -100,9 +100,23 @@ class RecentTestsData {
return null
}
fun computeConfigurationSuites() = runConfigurationSuites.values
.fold(arrayListOf(), { total: List<SuiteEntry>, entry: RunConfigurationEntry -> total + entry.suites })
fun getTestsToShow(): List<RecentTestsPopupEntry> {
val allEntries: List<RecentTestsPopupEntry> = runConfigurationSuites.values + urlSuites
return allEntries
val allConfigurationSuites = computeConfigurationSuites()
unmatchedRunConfigurationTests.forEach {
val currentTest = it
allConfigurationSuites.find { it.isMyTest(currentTest) }?.addTest(currentTest)
}
unmatchedUrlTests.forEach {
val currentTest = it
urlSuites.find { it.isMyTest(currentTest) }?.addTest(currentTest)
}
return (runConfigurationSuites.values + urlSuites)
.sortedByDescending { it.runDate }
.fold(listOf(), { popupList, currentEntry ->
popupList + currentEntry.getEntriesToShow()
@@ -20,7 +20,6 @@ import com.intellij.execution.testframework.sm.runner.states.TestStateInfo
import com.intellij.execution.testframework.sm.runner.states.TestStateInfo.Magnitude.*
import com.intellij.openapi.vfs.VirtualFileManager
import com.intellij.psi.PsiElement
import com.intellij.util.containers.ContainerUtil
import java.util.*
interface RecentTestsPopupEntry {
@@ -88,7 +87,7 @@ class SuiteEntry(url: String, magnitude: TestStateInfo.Magnitude, runDate: Date)
class RunConfigurationEntry(val runSettings: RunnerAndConfigurationSettings, initial: SuiteEntry) : RecentTestsPopupEntry {
val suites = ContainerUtil.newArrayList<SuiteEntry>()
val suites = arrayListOf<SuiteEntry>()
init {
addSuite(initial)
@@ -21,7 +21,6 @@ import com.intellij.execution.testframework.sm.runner.states.TestStateInfo.Magni
import com.intellij.testFramework.LightIdeaTestCase
import com.intellij.testIntegration.RecentTestsData
import org.assertj.core.api.Assertions.assertThat
import org.mockito.Mockito
import java.util.*
class RecentTestsOrderTest: LightIdeaTestCase() {
@@ -30,13 +29,10 @@ class RecentTestsOrderTest: LightIdeaTestCase() {
lateinit var allTests: RunnerAndConfigurationSettings
lateinit var now: Date
override fun setUp() {
super.setUp()
data = RecentTestsData()
allTests = Mockito.mock(RunnerAndConfigurationSettings::class.java)
Mockito.`when`(allTests.uniqueID).thenAnswer { "JUnit.all tests" }
Mockito.`when`(allTests.name).thenAnswer { "all tests" }
allTests = mockConfiguration("all tests", "JUnit.all tests")
now = Date()
}
@@ -126,6 +122,52 @@ class RecentTestsOrderTest: LightIdeaTestCase() {
assertThat(tests[2].presentation).isEqualTo("all tests")
assertThat(tests[2].magnitude).isEqualTo(FAILED_INDEX)
}
fun `test single test run doesn't override suite status`() {
val singleTestConfig = mockConfiguration("single test", "Junit.single test")
val newNow = Date(now.time + 100000)
//current single test run
addFailedSuite("Test".suite(), newNow, singleTestConfig)
addFailedTest("Test.testOK".test(), newNow, singleTestConfig)
//previous all suite run
addPassedTest("Test.testOK".test(), now, allTests)
addFailedTest("Test.testFailed".test(), now, allTests)
val tests = data.getTestsToShow()
assertThat(tests).hasSize(3)
assertThat(tests[0].presentation).isEqualTo("Test.testOK")
assertThat(tests[0].magnitude).isEqualTo(FAILED_INDEX)
assertThat(tests[1].presentation).isEqualTo("Test.testFailed")
assertThat(tests[1].magnitude).isEqualTo(FAILED_INDEX)
assertThat(tests[2].presentation).isEqualTo("Test")
assertThat(tests[2].magnitude).isEqualTo(FAILED_INDEX)
}
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)
addFailedTest("Test.testFailed".test(), now, allTests)
//current single test run
addFailedSuite("Test".suite(), newNow, singleTestConfig)
addFailedTest("Test.testOK".test(), newNow, singleTestConfig)
val tests = data.getTestsToShow()
assertThat(tests).hasSize(3)
assertThat(tests[0].presentation).isEqualTo("Test.testOK")
assertThat(tests[1].presentation).isEqualTo("Test.testFailed")
assertThat(tests[2].presentation).isEqualTo("Test")
}
}
@@ -28,6 +28,13 @@ import java.util.*
fun String.suite() = "java:suite://$this"
fun String.test() = "java:test://$this"
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
@@ -37,9 +44,7 @@ class RecentTestsStepTest: LightIdeaTestCase() {
override fun setUp() {
super.setUp()
data = RecentTestsData()
allTests = mock(RunnerAndConfigurationSettings::class.java)
`when`(allTests.uniqueID).thenAnswer { "JUnit.all tests" }
`when`(allTests.name).thenAnswer { "all tests" }
allTests = mockConfiguration("all tests", "JUnit.all tests")
now = Date()
}