Skip to content

Commit

Permalink
Extend more test configurations
Browse files Browse the repository at this point in the history
  • Loading branch information
pmendelski committed Aug 18, 2021
1 parent 48d30e5 commit cd0c3ca
Show file tree
Hide file tree
Showing 3 changed files with 156 additions and 21 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changelog

## [Unreleased]
- Support more configurations. Required by Lombok. ([issue #10](https://github.com/coditory/gradle-integration-test-plugin/issues/10))

## [1.2.3] - 2021-07-20
### Changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,29 +29,26 @@ internal object IntegrationTestTaskConfiguration {
}

private fun setupConfiguration(project: Project) {
val capitalizedName = INTEGRATION_CONFIG_PREFIX.capitalize()
project.configurations.getByName("${INTEGRATION_CONFIG_PREFIX}Implementation") {
it.extendsFrom(project.configurations.getByName("testImplementation"))
listOf(
"testAnnotationProcessor",
"testCompile",
"testCompileClasspath",
"testCompileOnly",
"testImplementation",
"testRuntime",
"testRuntimeClasspath",
"testRuntimeOnly"
)
.filter { project.configurations.names.contains(it) }
.forEach { setupConfiguration(project, it) }
}

private fun setupConfiguration(project: Project, testConfigName: String) {
val integrationConfigName = testConfigName.replaceFirst("test", INTEGRATION_CONFIG_PREFIX)
project.configurations.getByName(integrationConfigName) {
it.extendsFrom(project.configurations.getByName(testConfigName))
it.isVisible = true
it.isTransitive = true
it.description = "$capitalizedName Implementation"
}
if (project.configurations.names.contains("testRuntimeOnly")) {
// gradle 7
project.configurations.getByName("${INTEGRATION_CONFIG_PREFIX}RuntimeOnly") {
it.extendsFrom(project.configurations.getByName("testRuntimeOnly"))
it.isVisible = true
it.isTransitive = true
it.description = "$capitalizedName Runtime Only"
}
} else {
// gradle <7
project.configurations.getByName("${INTEGRATION_CONFIG_PREFIX}Runtime") {
it.extendsFrom(project.configurations.getByName("testRuntime"))
it.isVisible = true
it.isTransitive = true
it.description = "$capitalizedName Runtime"
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
package com.coditory.gradle.integration.acceptance

import com.coditory.gradle.integration.base.TestProjectBuilder.Companion.project
import com.coditory.gradle.integration.base.TestProjectRunner.runGradle
import org.assertj.core.api.Assertions.assertThat
import org.gradle.api.Project
import org.gradle.testkit.runner.TaskOutcome
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.ValueSource

class LombokAcceptanceTest {
private val project = createProject()

private fun createProject(): Project {
val commonImports =
"""
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
""".trimIndent()
return project("sample-lombok-project")
.withBuildGradle(
"""
plugins {
id 'com.coditory.integration-test'
}
repositories {
jcenter()
}
dependencies {
compileOnly "org.projectlombok:lombok:1.18.20"
annotationProcessor "org.projectlombok:lombok:1.18.20"
testCompileOnly "org.projectlombok:lombok:1.18.20"
testAnnotationProcessor "org.projectlombok:lombok:1.18.20"
testImplementation "org.junit.jupiter:junit-jupiter-api:5.5.1"
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:5.5.1"
}
test {
useJUnitPlatform()
testLogging {
events("passed", "failed", "skipped")
setExceptionFormat("full")
}
}
"""
).withFile(
"src/main/java/MainValueExample.java",
"""
import lombok.Value;
@Value
public class MainValueExample {
private final String name;
}
"""
).withFile(
"src/test/java/TestValueExample.java",
"""
import lombok.Value;
@Value
public class TestValueExample {
private final String name;
}
"""
).withFile(
"src/integration/java/IntgValueExample.java",
"""
import lombok.Value;
@Value
public class IntgValueExample {
private final String name;
}
"""
).withFile(
"src/integration/java/TestIntgSpec.java",
"""
$commonImports
public class TestIntgSpec {
@Test
public void shouldValueObjectsFromMain() {
assertEquals(new MainValueExample("X"), new MainValueExample("X"));
assertNotEquals(new MainValueExample("X"), new MainValueExample("Y"));
}
@Test
public void shouldValueObjectsFromTest() {
assertEquals(new TestValueExample("X"), new TestValueExample("X"));
assertNotEquals(new TestValueExample("X"), new TestValueExample("Y"));
}
@Test
public void shouldValueObjectsFromIntegration() {
assertEquals(new IntgValueExample("X"), new IntgValueExample("X"));
assertNotEquals(new IntgValueExample("X"), new IntgValueExample("Y"));
}
}
"""
).withFile(
"src/test/java/TestUnitSpec.java",
"""
$commonImports
public class TestUnitSpec {
@Test
public void shouldValueObjectsFromMain() {
assertEquals(new MainValueExample("X"), new MainValueExample("X"));
assertNotEquals(new MainValueExample("X"), new MainValueExample("Y"));
}
@Test
public void shouldValueObjectsFromTest() {
assertEquals(new TestValueExample("X"), new TestValueExample("X"));
assertNotEquals(new TestValueExample("X"), new TestValueExample("Y"));
}
}
"""
)
.build()
}

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

0 comments on commit cd0c3ca

Please sign in to comment.