Gradle (Kotlin DSL) 测试未执行

Gradle (Kotlin DSL) tests not executed

我有一个多项目设置,但想运行在一个子项目中进行测试。

我的文件结构遵循约定:

+ common-scripting
  + src
    + main
      + kotlin
      + resources
    + test
      + kotlin
         + scripting
            + ValueTest.kt
      + resources

在我的 ValueTest.kt 中,我有一个虚拟测试用例:

package scripting

import org.testng.Assert.assertTrue
import org.testng.annotations.Test

class ValueTest {

    @Test
    fun testIt() {
        assertTrue(false)
    }
}

我的构建脚本是这样的:

repositories {
    mavenCentral()
}

plugins {
    kotlin("jvm")
    java
}

dependencies {
    compile(kotlin("stdlib-jdk8"))
    compile(kotlin("script-runtime"))
    compile(kotlin("script-util"))
    compile(kotlin("compiler-embeddable"))

    testImplementation("org.testng:testng:6.14.3")
}

然而,当我 运行 测试时:

> gradlew.bat --info :common-scripting:cleanTest :common-scripting:test

> Task :common-scripting:clean
Task ':common-scripting:clean' is not up-to-date because:
  Task has not declared any outputs despite executing actions.

> Task :common-scripting:compileKotlin
Task ':common-scripting:compileKotlin' is not up-to-date because:
  Output property 'destinationDir' file C:\balage\git\rlog_legacy\_rlog\common-scripting\build\classes\kotlin\main has been removed.
  Output property 'destinationDir' file C:\balage\git\rlog_legacy\_rlog\common-scripting\build\classes\kotlin\main\META-INF has been removed.
  Output property 'destinationDir' file C:\balage\git\rlog_legacy\_rlog\common-scripting\build\classes\kotlin\main\META-INF\common-scripting.kotlin_module has been removed.
All input files are considered out-of-date for incremental task ':common-scripting:compileKotlin'.
Using Kotlin incremental compilation
Options for KOTLIN DAEMON: IncrementalCompilationOptions(super=CompilationOptions(compilerMode=INCREMENTAL_COMPILER, targetPlatform=JVM, reportCategories=[0], reportSeverity=2, requestedCompi
lationResults=[0]), areFileChangesKnown=false, modifiedFiles=null, deletedFiles=null, workingDir=C:\balage\git\rlog_legacy\_rlog\common-scripting\build\kotlin\compileKotlin, customCacheVersio
nFileName='gradle-format-version.txt', customCacheVersion=4, multiModuleICSettings=MultiModuleICSettings(buildHistoryFile=C:\balage\git\rlog_legacy\_rlog\common-scripting\build\kotlin\compile
Kotlin\build-history.bin, useModuleDetection=false), usePreciseJavaTracking=truelocalStateDirs=[C:\balage\git\rlog_legacy\_rlog\common-scripting\build\classes\kotlin\main])


> Task :common-scripting:compileJava NO-SOURCE
Skipping task ':common-scripting:compileJava' as it has no source files and no previous output files.

> Task :common-scripting:processResources
Task ':common-scripting:processResources' is not up-to-date because:
  Output property 'destinationDir' file C:\balage\git\rlog_legacy\_rlog\common-scripting\build\resources\main has been removed.
  Output property 'destinationDir' file C:\balage\git\rlog_legacy\_rlog\common-scripting\build\resources\main\META-INF has been removed.
  Output property 'destinationDir' file C:\balage\git\rlog_legacy\_rlog\common-scripting\build\resources\main\META-INF\services has been removed.

> Task :common-scripting:classes
Skipping task ':common-scripting:classes' as it has no actions.

> Task :common-scripting:compileTestKotlin
Task ':common-scripting:compileTestKotlin' is not up-to-date because:
  Output property 'destinationDir' file C:\balage\git\rlog_legacy\_rlog\common-scripting\build\classes\kotlin\test has been removed.
  Output property 'destinationDir' file C:\balage\git\rlog_legacy\_rlog\common-scripting\build\classes\kotlin\test\META-INF has been removed.
  Output property 'destinationDir' file C:\balage\git\rlog_legacy\_rlog\common-scripting\build\classes\kotlin\test\META-INF\common-scripting.kotlin_module has been removed.
All input files are considered out-of-date for incremental task ':common-scripting:compileTestKotlin'.
Using Kotlin incremental compilation
Options for KOTLIN DAEMON: IncrementalCompilationOptions(super=CompilationOptions(compilerMode=INCREMENTAL_COMPILER, targetPlatform=JVM, reportCategories=[0], reportSeverity=2, requestedCompi
lationResults=[0]), areFileChangesKnown=false, modifiedFiles=null, deletedFiles=null, workingDir=C:\balage\git\rlog_legacy\_rlog\common-scripting\build\kotlin\compileTestKotlin, customCacheVe
rsionFileName='gradle-format-version.txt', customCacheVersion=4, multiModuleICSettings=MultiModuleICSettings(buildHistoryFile=C:\balage\git\rlog_legacy\_rlog\common-scripting\build\kotlin\com
pileTestKotlin\build-history.bin, useModuleDetection=false), usePreciseJavaTracking=truelocalStateDirs=[C:\balage\git\rlog_legacy\_rlog\common-scripting\build\classes\kotlin\test])

> Task :common-scripting:compileTestJava NO-SOURCE
Skipping task ':common-scripting:compileTestJava' as it has no source files and no previous output files.

> Task :common-scripting:processTestResources
Task ':common-scripting:processTestResources' is not up-to-date because:
  Output property 'destinationDir' file C:\balage\git\rlog_legacy\_rlog\common-scripting\build\resources\test has been removed.
  Output property 'destinationDir' file C:\balage\git\rlog_legacy\_rlog\common-scripting\build\resources\test\empty.txt has been removed.

> Task :common-scripting:testClasses
Skipping task ':common-scripting:testClasses' as it has no actions.

> Task :common-scripting:test
Task ':common-scripting:test' is not up-to-date because:
  Output property 'binResultsDir' file C:\balage\git\rlog_legacy\_rlog\common-scripting\build\test-results\test\binary has been removed.
  Output property 'binResultsDir' file C:\balage\git\rlog_legacy\_rlog\common-scripting\build\test-results\test\binary\output.bin has been removed.
  Output property 'binResultsDir' file C:\balage\git\rlog_legacy\_rlog\common-scripting\build\test-results\test\binary\output.bin.idx has been removed.
Finished generating test XML results (0.0 secs) into: C:\balage\git\rlog_legacy\_rlog\common-scripting\build\test-results\test
Generating HTML test report...
Finished generating test html results (0.009 secs) into: C:\balage\git\rlog_legacy\_rlog\common-scripting\build\reports\tests\test

BUILD SUCCESSFUL in 4s
12 actionable tasks: 6 executed, 6 up-to-date

它运行s,甚至执行了测试任务,但是执行了none个测试。我查看了IDEA中的源码目录配置,包含测试路径,所以IDEA检测到了。

哪里出了问题?

当我尝试从 IDEA 执行测试时,出现以下错误:

> Task :common-scripting:test FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':common-scripting:test'.
> No tests found for given includes: [scripting.ValueTest](filter.includeTestsMatching)
* 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
BUILD FAILED in 1s
12 actionable tasks: 2 executed, 10 up-to-date
No tests found for given includes: [scripting.ValueTest](filter.includeTestsMatching)
17:09:04: Tasks execution finished ':common-scripting:cleanTest :common-scripting:test --tests "scripting.ValueTest"'.

您还没有告诉 the test task 使用 TestNG:

tasks.getByName<Test>("test") {
    useTestNG()
}