'Failed to run unit test of java code in kotling spring project
so I'm trying to do a unit testing java codes using Junit in a spring boot kotlin project, the codes are as following.
class JavaTestClass {
@Test
void javaTest(){
List<String> mylist = getStringList();
}
List<String> getStringList() {
ArrayList<String> stringList = new ArrayList<String>(List.of(new String[]{"Apple", "Banana", "Cherry",""}));
ArrayList<String> withoutBlank = new ArrayList(stringList.stream().filter(f -> !f.isBlank()).collect(Collectors.toList()));
return withoutBlank;
}
}
which is just a test for removing blanks from a list. This code runs without a problem when i test it in a java project, but when i test it in a kotlin project, it shows the error below.
FAILURE: Build failed with an exception.
- What went wrong: Execution failed for task ':test'.
No tests found for given includes: ...packagename
- Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
- Get more help at https://help.gradle.org
this is my build.gradle.kts file looks like
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
id("org.springframework.boot") version "2.6.6"
id("io.spring.dependency-management") version "1.0.11.RELEASE"
kotlin("jvm") version "1.6.10"
kotlin("plugin.spring") version "1.6.10"
}
group = "com.fullstack.kotlin.spring"
version = "0.0.1-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_16
repositories {
mavenCentral()
}
dependencies {
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
// providedRuntime("org.springframework.boot:spring-boot-starter-tomcat")
//coroutine
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.1")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-reactor:1.6.1")
testImplementation("org.springframework.boot:spring-boot-starter-test")
runtimeOnly ("com.h2database:h2")
}
tasks.withType<KotlinCompile> {
kotlinOptions {
freeCompilerArgs = listOf("-Xjsr305=strict")
jvmTarget = "16"
}
}
tasks.withType<Test> {
useJUnitPlatform()
}
Is there anyhthing im missing, or needed to add in order to do unit test with java in kotlin project
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
