aledsdavies / springboot_template

This is an example Spring Boot app written in Kotlin and build using Bazel
MIT License
0 stars 1 forks source link

Unit tests in Kotlin? #1

Open johnburbridge opened 2 months ago

johnburbridge commented 2 months ago

Thanks for putting this together @aledsdavies!

I realize it's been 3 years but would you have any further thoughts on how to instrument the build for unit tests written in kotlin using the kt_jvm_test provided by rules_kotlin?

https://bazelbuild.github.io/rules_kotlin/kotlin#kt_jvm_test

I've been stuck trying to get it to work to no avail.

load("@rules_kotlin//kotlin:core.bzl", "define_kt_toolchain")
load("@rules_kotlin//kotlin:jvm.bzl", "kt_jvm_library", "kt_jvm_test")

KOTLIN_LANGUAGE_LEVEL = "1.9"

JAVA_LANGUAGE_LEVEL = "21"

define_kt_toolchain(
    name = "kotlin_toolchain",
    api_version = KOTLIN_LANGUAGE_LEVEL,
    jvm_target = JAVA_LANGUAGE_LEVEL,
    language_version = KOTLIN_LANGUAGE_LEVEL,
)

kt_jvm_test(
    name = "service_api_tests",
    srcs = glob(["**/*.kt"]),
    main_class = "org.junit.platform.console.ConsoleLauncher",
    resources = [
        "//service/api/src/test/resources",
    ],
    deps = [
        "//service/api/src/main/kotlin/com/my/service:service_api_lib",
        "//thirdparty:spring-boot-starter-test",
        "//thirdparty:junit5-jupiter",
        "//thirdparty:kotlin-test-junit5",
    ],
)
aledsdavies commented 2 months ago

I actually left that company not long after I was experimenting with this and haven't had an opportunity to look at bazel since then so I wont be able to help you. Hopefully you find a solution