Skip to content

Commit

Permalink
Add a failing test for JUnit 5 extensions
Browse files Browse the repository at this point in the history
I looked into implementing this and it gets ugly quite quickly.
I believe the best implementation applies Burst's transformation
only to recognized parameters (enums, booleans, burstValues) and
preserves existing behavior otherwise. Unfortunately the code to
implement this is pretty tricky.

I've decided to not implement this behavior for now. If it's
requested we can reconsider.
  • Loading branch information
squarejesse committed Nov 12, 2024
1 parent 97c329e commit 7c63761
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ import assertk.assertions.containsExactlyInAnyOrder
import assertk.assertions.isEqualTo
import assertk.assertions.isFalse
import assertk.assertions.isIn
import assertk.assertions.matches
import java.io.File
import org.gradle.testkit.runner.GradleRunner
import org.gradle.testkit.runner.TaskOutcome
import org.jetbrains.kotlin.konan.target.HostManager
import org.jetbrains.kotlin.konan.target.presetName
import org.junit.Ignore
import org.junit.Test

class BurstGradlePluginTest {
Expand Down Expand Up @@ -286,6 +288,34 @@ class BurstGradlePluginTest {
}
}

@Test
@Ignore("mixing JUnit 5 and Burst parameters is not supported")
fun junit5Extensions() {
val projectDir = File("src/test/projects/junit5Extensions")

val taskName = ":lib:test"
val result = createRunner(projectDir, "clean", taskName).build()
assertThat(result.task(taskName)!!.outcome).isIn(*SUCCESS_OUTCOMES)

val testResults = projectDir.resolve("lib/build/test-results")

with(readTestSuite(testResults.resolve("test/TEST-TempDirTest.xml"))) {
assertThat(testCases.map { it.name }).containsExactlyInAnyOrder(
"test()",
"test_b()",
)
assertThat(systemOut).matches(
Regex(
"""
|running \S+ b
|running \S+ a
|
""".trimMargin()
)
)
}
}

private fun createRunner(
projectDir: File,
vararg taskNames: String,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile

buildscript {
repositories {
maven {
url = file("$rootDir/../../../../../build/testMaven").toURI()
}
mavenCentral()
google()
}
dependencies {
classpath("app.cash.burst:burst-gradle-plugin:${project.property("burstVersion")}")
classpath(libs.kotlin.gradlePlugin)
}
}

allprojects {
repositories {
maven {
url = file("$rootDir/../../../../../build/testMaven").toURI()
}
mavenCentral()
google()
}

tasks.withType(JavaCompile::class.java).configureEach {
sourceCompatibility = "1.8"
targetCompatibility = "1.8"
}

tasks.withType(KotlinJvmCompile::class.java).configureEach {
compilerOptions {
jvmTarget.set(JvmTarget.JVM_1_8)
}
}

tasks.withType<Test> {
useJUnitPlatform()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
plugins {
kotlin("jvm")
id("app.cash.burst")
}

dependencies {
testImplementation(kotlin("test"))
testImplementation(libs.junit)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import app.cash.burst.Burst
import app.cash.burst.burstValues
import java.io.File
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.io.TempDir

@Burst
class TempDirTest {
@Test
fun test(
@TempDir tempDir: File,
string: String = burstValues("a", "b"),
) {
println("running $tempDir $string")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
dependencyResolutionManagement {
versionCatalogs {
create("libs") {
from(files("../../../../../gradle/libs.versions.toml"))
}
}
}

include(":lib")

0 comments on commit 7c63761

Please sign in to comment.