gpt4 book ai didi

java - Gradle 不在命令行上执行任何测试

转载 作者:行者123 更新时间:2023-12-03 11:20:21 27 4
gpt4 key购买 nike

我的 Gradle 项目使用 KotlinDSL 和 JUnit5/Jupiter(以及 Kotlin 作为编程语言),Gradle 似乎没有正确地接受我的任何测试。当我在命令行上运行 Gradle test 时,它告诉我

SUCCESS: Executed 0 tests in 1s

无论我尝试什么。但是,在我的 IDE 中,我可以轻松地运行项目中的每个测试类而不会出现任何问题。

我的构建文件 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 注释进行注释。任何想法我可以尝试什么?它真的开始让我发疯。

非常感谢,伙计们!

康斯坦丁

最佳答案

看看这个:How to run Gradle test when all tests are UP-TO-DATE?
这可能是您遇到问题的原因和解决方法。

关于java - Gradle 不在命令行上执行任何测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57945331/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com