Skip to content

Commit

Permalink
Revert integration source name
Browse files Browse the repository at this point in the history
  • Loading branch information
pmendelski committed Oct 13, 2024
1 parent 9f066ef commit 2b224f4
Show file tree
Hide file tree
Showing 15 changed files with 71 additions and 40 deletions.
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,7 @@ If you're against adding plugins to your build file, simply copy-paste the confi

## Migrating from 1.x.x to 2.x.x

- Rename integration test source folder from `src/integration` to `src/integrationTest`.
- In `build.gradle[.kts]` file in `dependencies {}` section use `integrationTestImplementation(...)` instead of
`integrationImplementation(...)`.
- Skipping flags changed names. Use `skipTests`, `skipUnitTests`, `skipIntegrationTests`
instead of `skipTest`, `skipUnitTest`, `skipIntegrationTest`.
- Added integration with Jacoco - coverage from integration tests is automatically included in report.
- Integration with JUnit4 is removed.
- Integration with JUnit4 is dropped.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ open class IntegrationTestPlugin : Plugin<Project> {

companion object {
const val PLUGIN_ID = "com.coditory.integration-test"
const val INTEGRATION = "integration"
const val INTEGRATION_TEST = "integrationTest"
const val TEST_ALL_TASK_NAME = "testAll"
const val SKIP_UNIT_TEST_FLAG_NAME = "skipUnitTest"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.coditory.gradle.integration

import com.coditory.gradle.integration.IntegrationTestPlugin.Companion.INTEGRATION_TEST
import com.coditory.gradle.integration.IntegrationTestPlugin.Companion.INTEGRATION
import org.gradle.api.Project
import org.gradle.testing.jacoco.plugins.JacocoTaskExtension
import org.gradle.testing.jacoco.tasks.JacocoCoverageVerification
Expand All @@ -10,17 +10,17 @@ internal object JacocoTaskConfiguration {
fun apply(project: Project) {
if (project.pluginManager.hasPlugin("jacoco")) {
var dstFile: String? = null
project.tasks.named(INTEGRATION_TEST) { task ->
project.tasks.named(INTEGRATION) { task ->
val jacocoTaskExtension = task.extensions.getByType(JacocoTaskExtension::class.java)
dstFile = jacocoTaskExtension.destinationFile?.path
}
if (dstFile != null) {
project.tasks.withType(JacocoReport::class.java) { task ->
task.executionData(dstFile)
task.mustRunAfter(INTEGRATION_TEST)
task.mustRunAfter(INTEGRATION)
}
project.tasks.withType(JacocoCoverageVerification::class.java) { task ->
task.mustRunAfter(INTEGRATION_TEST)
task.mustRunAfter(INTEGRATION)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.coditory.gradle.integration

import com.coditory.gradle.integration.IntegrationTestPlugin.Companion.INTEGRATION_TEST
import com.coditory.gradle.integration.IntegrationTestPlugin.Companion.TEST_ALL_TASK_NAME
import com.coditory.gradle.integration.TestSkippingConditions.skipTestAll
import org.gradle.api.Project
Expand All @@ -15,5 +16,6 @@ internal object TestAllTaskConfiguration {
project.tasks.withType(Test::class.java).forEach {
testAllTask.dependsOn(it.name)
}
testAllTask.dependsOn(INTEGRATION_TEST)
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.coditory.gradle.integration

import com.coditory.gradle.integration.IntegrationTestPlugin.Companion.INTEGRATION
import com.coditory.gradle.integration.IntegrationTestPlugin.Companion.INTEGRATION_TEST
import com.coditory.gradle.integration.IntegrationTestPlugin.Companion.SKIP_INTEGRATION_TEST_FLAG_NAME
import com.coditory.gradle.integration.IntegrationTestPlugin.Companion.SKIP_TEST_ALL_FLAG_NAME
import com.coditory.gradle.integration.IntegrationTestPlugin.Companion.SKIP_UNIT_TEST_FLAG_NAME
Expand Down Expand Up @@ -28,7 +30,11 @@ internal object TestSkippingConditions {
}

private fun hasSkipIntegrationTestFlag(project: Project): Boolean {
return hasPropertyFlag(project, SKIP_INTEGRATION_TEST_FLAG_NAME)
return hasPropertyFlag(project, SKIP_INTEGRATION_TEST_FLAG_NAME) || hasExcludeIntegrationTestTaskParam(project)
}

private fun hasExcludeIntegrationTestTaskParam(project: Project): Boolean {
return hasExcludedTask(project, INTEGRATION_TEST) || hasExcludedTask(project, INTEGRATION)
}

private fun hasPropertyFlag(project: Project, name: String): Boolean {
Expand All @@ -38,4 +44,8 @@ internal object TestSkippingConditions {
}
return false
}

private fun hasExcludedTask(project: Project, name: String): Boolean {
return project.gradle.startParameter.excludedTaskNames.contains(name)
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.coditory.gradle.integration

import com.coditory.gradle.integration.IntegrationTestPlugin.Companion.INTEGRATION
import com.coditory.gradle.integration.IntegrationTestPlugin.Companion.INTEGRATION_TEST
import com.coditory.gradle.integration.TestSkippingConditions.skipIntegrationTest
import com.coditory.gradle.integration.TestSkippingConditions.skipUnitTest
Expand All @@ -9,6 +10,7 @@ import org.gradle.api.plugins.JavaBasePlugin
import org.gradle.api.plugins.JavaPluginExtension
import org.gradle.api.plugins.jvm.JvmTestSuite
import org.gradle.api.tasks.SourceSet
import org.gradle.language.base.plugins.LifecycleBasePlugin
import org.gradle.testing.base.TestingExtension

@Suppress("UnstableApiUsage")
Expand Down Expand Up @@ -38,7 +40,7 @@ internal object TestSuitesConfiguration {
task.onlyIf { !skipUnitTest(project) }
}
}
testing.suites.register(INTEGRATION_TEST, JvmTestSuite::class.java) {
testing.suites.register(INTEGRATION, JvmTestSuite::class.java) {
it.testType.set(TestSuiteType.INTEGRATION_TEST)
it.targets.all { target ->
target.testTask.configure { task ->
Expand All @@ -57,14 +59,22 @@ internal object TestSuitesConfiguration {
}

private fun setupTestTask(project: Project) {
val integrationTestTask = project.tasks.create(INTEGRATION_TEST)
integrationTestTask.description = "Runs integration test suites."
integrationTestTask.group = LifecycleBasePlugin.VERIFICATION_GROUP
integrationTestTask.onlyIf { !skipIntegrationTest(project) }
integrationTestTask.dependsOn(INTEGRATION)
project.tasks.getByName(JavaBasePlugin.CHECK_TASK_NAME)
.dependsOn(INTEGRATION_TEST)
project.tasks.getByName(JavaBasePlugin.CHECK_TASK_NAME)
.dependsOn(INTEGRATION)
project.tasks.getByName(INTEGRATION).onlyIf { !skipIntegrationTest(project) }
}

private fun configureKotlinCompilation(project: Project) {
val kotlin = project.extensions
.findByType(org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension::class.java) ?: return
kotlin.target.compilations.getByName(INTEGRATION_TEST) {
kotlin.target.compilations.getByName(INTEGRATION) {
val test = kotlin.target.compilations.getByName(SourceSet.TEST_SOURCE_SET_NAME)
it.associateWith(test)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class JacocoConfigurationTest {
assertThat(executionData.asPath).isEqualTo(
project.toBuildPath(
"jacoco/test.exec",
"jacoco/integrationTest.exec",
"jacoco/integration.exec",
),
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.coditory.gradle.integration

import com.coditory.gradle.integration.IntegrationTestPlugin.Companion.INTEGRATION
import com.coditory.gradle.integration.IntegrationTestPlugin.Companion.INTEGRATION_TEST
import com.coditory.gradle.integration.IntegrationTestPlugin.Companion.TEST_ALL_TASK_NAME
import com.coditory.gradle.integration.base.TestProjectBuilder.Companion.createProject
Expand All @@ -16,7 +17,7 @@ class TestAllTaskConfigurationTest {
@Test
fun `should configure testAll task`() {
val task = getTestAllTask()
assertThat(task.dependsOn).isEqualTo(setOf(TEST_TASK_NAME, INTEGRATION_TEST))
assertThat(task.dependsOn).isEqualTo(setOf(TEST_TASK_NAME, INTEGRATION, INTEGRATION_TEST))
assertThat(task.description).isEqualTo("Runs all test suites.")
assertThat(task.group).isEqualTo(VERIFICATION_GROUP)
assertThat(task.enabled).isEqualTo(true)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.coditory.gradle.integration

import com.coditory.gradle.integration.IntegrationTestPlugin.Companion.INTEGRATION
import com.coditory.gradle.integration.IntegrationTestPlugin.Companion.INTEGRATION_TEST
import com.coditory.gradle.integration.base.TestProjectBuilder.Companion.createProject
import com.coditory.gradle.integration.base.toBuildPath
Expand All @@ -20,8 +21,8 @@ class TestTaskConfigurationTest {
fun `should configure integration source sets`() {
val sourceSet = getSourceSet()
assertThat(sourceSet).isNotNull
assertThat(sourceSet.output.classesDirs.asPath).isEqualTo(project.toBuildPath("classes/java/integrationTest"))
assertThat(sourceSet.output.resourcesDir.toString()).isEqualTo(project.toBuildPath("resources/integrationTest"))
assertThat(sourceSet.output.classesDirs.asPath).isEqualTo(project.toBuildPath("classes/java/integration"))
assertThat(sourceSet.output.resourcesDir.toString()).isEqualTo(project.toBuildPath("resources/integration"))
// TODO: Fix it. Tried it all. It's failing with Could not find org.gradle.internal.impldep.org.junit.jupiter:junit-jupiter:5.8.2
// Tried: adding repositories to test project, defining tests to use junit platform etc - did not help...
// assertThat(sourceSet.runtimeClasspath.asPath)
Expand All @@ -42,7 +43,7 @@ class TestTaskConfigurationTest {
val integrationSourceSet = getSourceSet()
val task = getTestTask()
assertThat(task.testClassesDirs).isNotNull
assertThat(task.description).isEqualTo("Runs the integration test suite.")
assertThat(task.description).isEqualTo("Runs the integration suite.")
assertThat(task.group).isEqualTo(VERIFICATION_GROUP)
assertThat(task.testClassesDirs).isEqualTo(integrationSourceSet.output.classesDirs)
assertThat(task.classpath).isEqualTo(integrationSourceSet.runtimeClasspath)
Expand All @@ -58,13 +59,13 @@ class TestTaskConfigurationTest {
}

private fun getTestTask(): TestTask {
return project.tasks.getByName(INTEGRATION_TEST) as TestTask
return project.tasks.getByName(INTEGRATION) as TestTask
}

@Suppress("UnstableApiUsage")
private fun getSourceSet(project: Project = this.project): SourceSet {
return project.extensions.getByType(TestingExtension::class.java).suites
.getByName(INTEGRATION_TEST)
.getByName(INTEGRATION)
.let { it as JvmTestSuite }
.sources
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class CommandLineAcceptanceTest {
}
""",
).withFile(
"src/integrationTest/java/TestIntgSpec.java",
"src/integration/java/TestIntgSpec.java",
"""
$commonImports
Expand Down Expand Up @@ -84,7 +84,16 @@ class CommandLineAcceptanceTest {
val result = runGradle(project, listOf("check"), gradleVersion)
// then
assertThat(result.task(":test")?.outcome).isEqualTo(TaskOutcome.SUCCESS)
assertThat(result.task(":integrationTest")?.outcome).isEqualTo(TaskOutcome.SUCCESS)
assertThat(result.task(":integration")?.outcome).isEqualTo(TaskOutcome.SUCCESS)
}

@ParameterizedTest(name = "should run integration tests on integrationTest command for gradle {0}")
@ValueSource(strings = [GRADLE_MAX_SUPPORTED_VERSION, GRADLE_MIN_SUPPORTED_VERSION])
fun `should run integration tests on integrationTest command`(gradleVersion: String?) {
// when
val result = runGradle(project, listOf("integrationTest"), gradleVersion)
// then
assertThat(result.task(":integration")?.outcome).isEqualTo(TaskOutcome.SUCCESS)
}

@Test
Expand All @@ -93,7 +102,7 @@ class CommandLineAcceptanceTest {
val result = runGradle(project, listOf("test"))
// then
assertThat(result.task(":test")?.outcome).isEqualTo(TaskOutcome.SUCCESS)
assertThat(result.task(":integrationTest")?.outcome).isNull()
assertThat(result.task(":integration")?.outcome).isNull()
}

@Test
Expand All @@ -102,7 +111,7 @@ class CommandLineAcceptanceTest {
val result = runGradle(project, listOf("testAll"))
// then
assertThat(result.task(":test")?.outcome).isEqualTo(TaskOutcome.SUCCESS)
assertThat(result.task(":integrationTest")?.outcome).isEqualTo(TaskOutcome.SUCCESS)
assertThat(result.task(":integration")?.outcome).isEqualTo(TaskOutcome.SUCCESS)
}

@Test
Expand All @@ -111,7 +120,7 @@ class CommandLineAcceptanceTest {
val result = runGradle(project, listOf("check", "-x", "integrationTest"))
// then
assertThat(result.task(":test")?.outcome).isEqualTo(TaskOutcome.SUCCESS)
assertThat(result.task(":integrationTest")?.outcome).isNull()
assertThat(result.task(":integration")?.outcome).isEqualTo(TaskOutcome.SKIPPED)
}

@Test
Expand All @@ -120,7 +129,7 @@ class CommandLineAcceptanceTest {
val result = runGradle(project, listOf("check", "-PskipIntegrationTest"))
// then
assertThat(result.task(":test")?.outcome).isEqualTo(TaskOutcome.SUCCESS)
assertThat(result.task(":integrationTest")?.outcome).isEqualTo(TaskOutcome.SKIPPED)
assertThat(result.task(":integration")?.outcome).isEqualTo(TaskOutcome.SKIPPED)
}

@Test
Expand All @@ -129,7 +138,7 @@ class CommandLineAcceptanceTest {
val result = runGradle(project, listOf("check", "-PskipTest"))
// then
assertThat(result.task(":test")?.outcome).isEqualTo(TaskOutcome.SKIPPED)
assertThat(result.task(":integrationTest")?.outcome).isEqualTo(TaskOutcome.SKIPPED)
assertThat(result.task(":integration")?.outcome).isEqualTo(TaskOutcome.SKIPPED)
}

@Test
Expand All @@ -138,6 +147,6 @@ class CommandLineAcceptanceTest {
val result = runGradle(project, listOf("check", "-PskipUnitTest"))
// then
assertThat(result.task(":test")?.outcome).isEqualTo(TaskOutcome.SKIPPED)
assertThat(result.task(":integrationTest")?.outcome).isEqualTo(TaskOutcome.SUCCESS)
assertThat(result.task(":integration")?.outcome).isEqualTo(TaskOutcome.SUCCESS)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class JacocoBasedAcceptanceTest {
}
""",
).withFile(
"src/integrationTest/java/TestIntgSpec.java",
"src/integration/java/TestIntgSpec.java",
"""
$commonImports
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class Junit5BasedAcceptanceTest {
testImplementation "org.junit.jupiter:junit-jupiter-api:5.11.0"
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:5.11.0"
// sample integration test dependency
integrationTestImplementation "org.slf4j:slf4j-api:2.0.16"
integrationImplementation "org.slf4j:slf4j-api:2.0.16"
}
tasks.withType(Test) {
Expand Down Expand Up @@ -79,7 +79,7 @@ class Junit5BasedAcceptanceTest {
}
""",
).withFile(
"src/integrationTest/java/ConstantValues.java",
"src/integration/java/ConstantValues.java",
"""
public class ConstantValues {
public static final String MODULE = "integration";
Expand All @@ -100,7 +100,7 @@ class Junit5BasedAcceptanceTest {
}
""",
).withFile(
"src/integrationTest/java/TestIntgSpec.java",
"src/integration/java/TestIntgSpec.java",
"""
$commonImports
Expand Down Expand Up @@ -163,7 +163,7 @@ class Junit5BasedAcceptanceTest {
.withFile("src/main/resources/c.txt", "main-c")
.withFile("src/test/resources/b.txt", "test-b")
.withFile("src/test/resources/c.txt", "test-c")
.withFile("src/integrationTest/resources/c.txt", "integration-c")
.withFile("src/integration/resources/c.txt", "integration-c")
.build()
}

Expand All @@ -174,6 +174,6 @@ class Junit5BasedAcceptanceTest {
val result = runGradle(project, listOf("check"), gradleVersion)
// then
assertThat(result.task(":test")?.outcome).isEqualTo(TaskOutcome.SUCCESS)
assertThat(result.task(":integrationTest")?.outcome).isEqualTo(TaskOutcome.SUCCESS)
assertThat(result.task(":integration")?.outcome).isEqualTo(TaskOutcome.SUCCESS)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class KotlinInternalScopeAcceptanceTest {
testImplementation("org.junit.jupiter:junit-jupiter-api:5.11.0")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.11.0")
// sample integration test dependency
integrationTestImplementation("org.slf4j:slf4j-api:2.0.16")
integrationImplementation("org.slf4j:slf4j-api:2.0.16")
}
tasks.withType<Test> {
Expand All @@ -63,7 +63,7 @@ class KotlinInternalScopeAcceptanceTest {
}
""",
).withFile(
"src/integrationTest/kotlin/TestIntgSpec.kt",
"src/integration/kotlin/TestIntgSpec.kt",
"""
$commonImports
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class LombokAcceptanceTest {
}
""",
).withFile(
"src/integrationTest/java/IntgValueExample.java",
"src/integration/java/IntgValueExample.java",
"""
import lombok.Value;
Expand All @@ -80,7 +80,7 @@ class LombokAcceptanceTest {
}
""",
).withFile(
"src/integrationTest/java/TestIntgSpec.java",
"src/integration/java/TestIntgSpec.java",
"""
$commonImports
Expand Down
Loading

0 comments on commit 2b224f4

Please sign in to comment.