[英]Gradle does not execute any tests on commandline
我的 Gradle 項目正在使用 KotlinDSL 和 JUnit5 / Jupiter(以及 Kotlin 作為編程語言),Gradle 似乎沒有正確選擇我的任何測試。 當我在命令行上運行 Gradle 測試時,它告訴我
SUCCESS: Executed 0 tests in 1s
無論我嘗試什么。 但是,在我的 IDE 中,我可以輕松地運行項目中的每個測試 class 而不會出現任何問題。
我的構建文件 build.gradle.kts 如下所示:
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
id("org.springframework.boot") version "2.1.8.RELEASE"
id("io.spring.dependency-management") version "1.0.8.RELEASE"
id("com.adarshr.test-logger") version "1.7.0"
kotlin("jvm") version "1.2.71"
kotlin("plugin.spring") version "1.2.71"
kotlin("plugin.jpa") version "1.2.71"
}
group = "myprojectgroup"
version = "1.0-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_1_8
val junitVersion="5.5.2"
val mockitoVersion="2.28.2"
repositories {
mavenCentral()
}
dependencies {
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
implementation("org.flywaydb:flyway-core")
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
runtimeOnly("com.h2database:h2")
testImplementation("org.springframework.boot:spring-boot-starter-test")
testImplementation("org.junit.jupiter:junit-jupiter-api:$junitVersion")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:$junitVersion")
testCompile ("org.mockito:mockito-core:$mockitoVersion")
testCompile("org.mockito:mockito-junit-jupiter:$mockitoVersion")
}
tasks.withType<KotlinCompile> {
kotlinOptions {
freeCompilerArgs = listOf("-Xjsr305=strict")
jvmTarget = "1.8"
}
}
tasks.test {
useJUnitPlatform {
includeEngines("junit-jupiter")
}
}
測試類按預期位於 src/test/kotlin 下,測試方法使用正確的 org.junit.jupiter.api.Test 注釋進行注釋。 我可以嘗試什么想法? 它真的開始讓我發瘋。
非常感謝,伙計們!
康斯坦丁
看看這個: 當所有測試都是最新的時,如何運行 Gradle 測試? 這可能是您遇到問題的原因和解決方法。
tasks.test { scanForTestClasses = true useJUnitPlatform { includeEngines("junit-jupiter") } }
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.