Skip to content

Commit

Permalink
Enable JUnit Jupiter testing in Kotlin JVM projects by default
Browse files Browse the repository at this point in the history
- Add example test to Kotlin JVM App project
  • Loading branch information
tresat committed Nov 27, 2024
1 parent 22cd432 commit 6f56428
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,10 @@ kotlinJvmApplication {
implementation(project(":kotlin-jvm-util"))
implementation("com.google.guava:guava:32.1.3-jre")
}

testing {
dependencies {
implementation("org.junit.jupiter:junit-jupiter:5.10.2")
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.example

import com.example.utils.Utils
import org.junit.jupiter.api.Test

import org.junit.jupiter.api.Assertions.*

class UtilsTest {
@Test
fun testWelcome() {
val utils = Utils()
assertEquals("Welcome to the kotlin-jvm-utils library!", utils.welcome)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.gradle.api.experimental.kmp.internal.KotlinPluginSupport;
import org.gradle.api.internal.plugins.software.SoftwareType;
import org.gradle.api.plugins.ApplicationPlugin;
import org.gradle.api.tasks.testing.Test;

/**
* Creates a declarative {@link KotlinJvmApplication} DSL model, applies the official Kotlin and application plugin,
Expand Down Expand Up @@ -46,5 +47,7 @@ private void configureTesting(Project project, KotlinJvmApplication dslModel) {
configurations.getByName("testImplementation").fromDependencyCollector(dslModel.getTesting().getDependencies().getImplementation());
configurations.getByName("testCompileOnly").fromDependencyCollector(dslModel.getTesting().getDependencies().getCompileOnly());
configurations.getByName("testRuntimeOnly").fromDependencyCollector(dslModel.getTesting().getDependencies().getRuntimeOnly());

project.getTasks().withType(Test.class).configureEach(Test::useJUnitPlatform);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.gradle.api.experimental.jvm.internal.JvmPluginSupport;
import org.gradle.api.experimental.kmp.internal.KotlinPluginSupport;
import org.gradle.api.internal.plugins.software.SoftwareType;
import org.gradle.api.tasks.testing.Test;

/**
* Creates a declarative {@link KotlinJvmApplication} DSL model, applies the official Kotlin and application plugin,
Expand Down Expand Up @@ -40,5 +41,7 @@ private void configureTesting(Project project, KotlinJvmLibrary dslModel) {
configurations.getByName("testImplementation").fromDependencyCollector(dslModel.getTesting().getDependencies().getImplementation());
configurations.getByName("testCompileOnly").fromDependencyCollector(dslModel.getTesting().getDependencies().getCompileOnly());
configurations.getByName("testRuntimeOnly").fromDependencyCollector(dslModel.getTesting().getDependencies().getRuntimeOnly());

project.getTasks().withType(Test.class).configureEach(Test::useJUnitPlatform);
}
}

0 comments on commit 6f56428

Please sign in to comment.