-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3797778
commit 1afdd9c
Showing
15 changed files
with
212 additions
and
58 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* @coditory/reviewers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
src/main/kotlin/com/coditory/gradle/integration/JacocoTaskConfiguration.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.coditory.gradle.integration | ||
|
||
import com.coditory.gradle.integration.IntegrationTestPlugin.Companion.INTEGRATION_TEST | ||
import org.gradle.api.Project | ||
import org.gradle.testing.jacoco.plugins.JacocoTaskExtension | ||
import org.gradle.testing.jacoco.tasks.JacocoCoverageVerification | ||
import org.gradle.testing.jacoco.tasks.JacocoReport | ||
|
||
internal object JacocoTaskConfiguration { | ||
fun apply(project: Project) { | ||
if (project.pluginManager.hasPlugin("jacoco")) { | ||
var dstFile: String? = null | ||
project.tasks.named(INTEGRATION_TEST) { 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) | ||
} | ||
project.tasks.withType(JacocoCoverageVerification::class.java) { task -> | ||
task.mustRunAfter(INTEGRATION_TEST) | ||
} | ||
} | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/test/kotlin/com/coditory/gradle/integration/JacocoConfigurationTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.coditory.gradle.integration | ||
|
||
import com.coditory.gradle.integration.base.TestProjectBuilder.Companion.project | ||
import com.coditory.gradle.integration.base.toBuildPath | ||
import org.assertj.core.api.Assertions.assertThat | ||
import org.gradle.api.Project | ||
import org.gradle.api.plugins.JavaPlugin | ||
import org.gradle.testing.jacoco.plugins.JacocoPlugin | ||
import org.gradle.testing.jacoco.tasks.JacocoReport | ||
import org.junit.jupiter.api.Test | ||
|
||
class JacocoConfigurationTest { | ||
private val project: Project = project() | ||
.withPlugins(JavaPlugin::class, JacocoPlugin::class, IntegrationTestPlugin::class) | ||
.build() | ||
|
||
@Test | ||
fun `should register integrationTest exec files in jacoco report task`() { | ||
val jacocoReportTask = project.tasks.getByName("jacocoTestReport") as JacocoReport | ||
val executionData = jacocoReportTask.executionData | ||
assertThat(executionData).isNotNull() | ||
assertThat(executionData.asPath).isEqualTo( | ||
project.toBuildPath( | ||
"jacoco/test.exec", | ||
"jacoco/integrationTest.exec", | ||
), | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
src/test/kotlin/com/coditory/gradle/integration/acceptance/JacocoBasedAcceptanceTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
package com.coditory.gradle.integration.acceptance | ||
|
||
import com.coditory.gradle.integration.base.GradleTestVersions.GRADLE_MAX_SUPPORTED_VERSION | ||
import com.coditory.gradle.integration.base.TestProjectBuilder.Companion.project | ||
import com.coditory.gradle.integration.base.TestProjectRunner.runGradle | ||
import com.coditory.gradle.integration.base.readFileFromBuildDir | ||
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 JacocoBasedAcceptanceTest { | ||
private val project = createProject() | ||
|
||
private fun createProject(): Project { | ||
val commonImports = | ||
""" | ||
import org.junit.jupiter.api.Test; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
""".trimIndent() | ||
return project("sample-project") | ||
.withBuildGradle( | ||
""" | ||
plugins { | ||
id 'jacoco' | ||
id 'com.coditory.integration-test' | ||
} | ||
repositories { | ||
mavenCentral() | ||
} | ||
dependencies { | ||
testImplementation "org.junit.jupiter:junit-jupiter-api:5.11.0" | ||
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:5.11.0" | ||
} | ||
tasks.withType(Test) { | ||
useJUnitPlatform() | ||
testLogging { | ||
events("passed", "failed", "skipped") | ||
setExceptionFormat("full") | ||
} | ||
} | ||
jacocoTestReport { | ||
reports { | ||
xml.required = true | ||
} | ||
} | ||
""", | ||
).withFile( | ||
"src/main/java/Calculator.java", | ||
""" | ||
public class Calculator { | ||
public static int add(int a, int b) { | ||
return a + b; | ||
} | ||
public static int subtract(int a, int b) { | ||
return a - b; | ||
} | ||
} | ||
""", | ||
).withFile( | ||
"src/integrationTest/java/TestIntgSpec.java", | ||
""" | ||
$commonImports | ||
public class TestIntgSpec { | ||
@Test | ||
public void shouldSubtract() { | ||
assertEquals(3, Calculator.subtract(6, 3)); | ||
} | ||
} | ||
""", | ||
).withFile( | ||
"src/test/java/TestUnitSpec.java", | ||
""" | ||
$commonImports | ||
public class TestUnitSpec { | ||
@Test | ||
public void shouldAdd() { | ||
assertEquals(9, Calculator.add(6, 3)); | ||
} | ||
} | ||
""", | ||
) | ||
.build() | ||
} | ||
|
||
@ParameterizedTest(name = "should aggregate coverage from unit and integration tests when using Jacoco {0}") | ||
// @ValueSource(strings = [GRADLE_MAX_SUPPORTED_VERSION, GRADLE_MIN_SUPPORTED_VERSION]) | ||
@ValueSource(strings = [GRADLE_MAX_SUPPORTED_VERSION]) | ||
fun `should aggregate coverage from unit and integration tests when using Jacoco`(gradleVersion: String?) { | ||
// when | ||
val result = | ||
runGradle(project, listOf("check", "jacocoTestReport"), gradleVersion) | ||
// then | ||
assertThat(result.task(":test")?.outcome).isEqualTo(TaskOutcome.SUCCESS) | ||
assertThat(result.task(":integrationTest")?.outcome).isEqualTo(TaskOutcome.SUCCESS) | ||
assertThat(project.readFileFromBuildDir("reports/jacoco/test/jacocoTestReport.xml")) | ||
// missed method is the init | ||
.contains("<counter type=\"METHOD\" missed=\"1\" covered=\"2\"/>") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.