我们在main
中有一些测试(因此它们可以内置到服务中并从中运行)。最新的Gradle默认不将main
中的源识别为测试代码。
我以为可以使用Nebula Facets插件,但是以下方法也无法解决该问题:
facets {
functionalTest {
parentSourceSet = 'main'
includeInCheckLifecycle = false
}
}
最佳答案
如果您确实需要使用src/main/java
进行测试,则不需要额外的源集。
相反,您需要配置一个测试任务,以便它使用main
源集的类路径。
这是一个使用Kotlin DSL和避免任务配置的配置此类测试任务的示例:
val mainTest = tasks.register<Test>("mainTest") {
useJUnitPlatform()
description = "Run tests from main"
group = "verification"
testClassesDirs = sourceSets["main"].output.classesDirs
classpath = sourceSets["main"].runtimeClasspath
}
tasks.named("check").configure {
dependsOn(mainTest)
}
关于gradle - 如何强制Gradle在 `main`中进行测试?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61879650/