Files
openide/plugins/gradle/java/testSources/execution/test/ExternalTestsModelCompatibilityTest.kt
Sergei Vorobyov f5db8fcafb IDEA-342292 [Gradle|Sync] cleanup: removed redundant tests filters for Gradle versions older than 4.5
The minimum supported Gradle version is 4.5.

GitOrigin-RevId: 0528007aff0fa426a9925b3a2bf449f3c2f19d7e
2024-01-12 12:49:17 +00:00

101 lines
4.0 KiB
Kotlin

// Copyright 2000-2020 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 org.jetbrains.plugins.gradle.execution.test
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.testFramework.runInEdtAndGet
import org.jetbrains.plugins.gradle.execution.test.runner.GradleTestRunConfigurationProducer.findAllTestsTaskToRun
import org.jetbrains.plugins.gradle.importing.GradleImportingTestCase
import org.jetbrains.plugins.gradle.tooling.annotation.TargetVersions
import org.junit.Assert
import org.junit.Test
class ExternalTestsModelCompatibilityTest : GradleImportingTestCase() {
@Test
fun `test simple tests finding`() {
val buildScript = createBuildScriptBuilder()
.withJavaPlugin()
.withJUnit4()
importProject(buildScript.generate())
assertTestTasks(createProjectSubFile("src/test/java/package/TestCase.java", "class TestCase"),
listOf(":test"))
}
@Test
@TargetVersions("<5.0")
fun `test intellij tests finding`() {
val buildScript = createBuildScriptBuilder()
.withJavaPlugin()
.withJUnit4()
.addPrefix("""
sourceSets {
foo.java.srcDirs = ["foo-src", "foo-other-src"]
foo.compileClasspath += sourceSets.test.runtimeClasspath
}
""".trimIndent())
.addPrefix("""
task 'foo test task'(type: Test) {
testClassesDir = sourceSets.foo.output.classesDir
classpath += sourceSets.foo.runtimeClasspath
}
task 'super foo test task'(type: Test) {
testClassesDir = sourceSets.foo.output.classesDir
classpath += sourceSets.foo.runtimeClasspath
}
""".trimIndent())
importProject(buildScript.generate())
assertTestTasks(createProjectSubFile("foo-src/package/TestCase.java", "class TestCase"),
listOf(":foo test task"),
listOf(":super foo test task"))
assertTestTasks(createProjectSubFile("foo-other-src/package/TestCase.java", "class TestCase"),
listOf(":foo test task"),
listOf(":super foo test task"))
}
@Test
fun `test intellij tests finding new interface`() {
val buildScript = createBuildScriptBuilder()
.withJavaPlugin()
.withJUnit4()
.addPrefix("""
sourceSets {
foo.java.srcDirs = ["foo-src", "foo-other-src"]
foo.compileClasspath += sourceSets.test.runtimeClasspath
}
""".trimIndent())
.addPrefix(
if (isGradleOlderThan("8.2")) {
"""
task 'foo test task'(type: Test) {
testClassesDirs = sourceSets.foo.output.classesDirs
classpath += sourceSets.foo.runtimeClasspath
}
task 'super foo test task'(type: Test) {
testClassesDirs = sourceSets.foo.output.classesDirs
classpath += sourceSets.foo.runtimeClasspath
}
""".trimIndent()
} else { """
task 'foo test task'(type: Test) {
testClassesDirs = sourceSets.foo.output.classesDirs
classpath = testing.suites.test.sources.runtimeClasspath + sourceSets.foo.runtimeClasspath
}
task 'super foo test task'(type: Test) {
testClassesDirs = sourceSets.foo.output.classesDirs
classpath = testing.suites.test.sources.runtimeClasspath + sourceSets.foo.runtimeClasspath
}
""".trimIndent()
})
importProject(buildScript.generate())
assertTestTasks(createProjectSubFile("foo-src/package/TestCase.java", "class TestCase"),
listOf(":foo test task"),
listOf(":super foo test task"))
assertTestTasks(createProjectSubFile("foo-other-src/package/TestCase.java", "class TestCase"),
listOf(":foo test task"),
listOf(":super foo test task"))
}
private fun assertTestTasks(source: VirtualFile, vararg expected: List<String>) {
val tasks = runInEdtAndGet { findAllTestsTaskToRun(source, myProject) }
Assert.assertEquals(expected.toList(), tasks)
}
}