简体   繁体   English

Gradle(Kotlin DSL)测试未执行

[英]Gradle (Kotlin DSL) tests not executed

I have a multi project setup, but would like to run a test in a subproject. 我有一个多项目设置,但想在子项目中运行测试。

My file structure follows conventions: 我的文件结构遵循约定:

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

In my ValueTest.kt I have a dummy test case: 在我的ValueTest.kt中,我有一个虚拟测试用例:

package scripting

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

class ValueTest {

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

My build script is this: 我的构建脚本是这样的:

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")
}

However, when I run the tests: 但是,当我运行测试时:

> 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

It runs, even executes the test task, but none of the tests are executed. 它运行,甚至执行测试任务,但没有执行任何测试。 I checked the source directory configuration in IDEA, and the test path is included, so IDEA detects them. 我在IDEA中检查了源目录配置,并且包含了测试路径,因此IDEA会检测它们。

What did go wrong? 出了什么问题?

When I try to execute tests from IDEA, it gives the following error: 当我尝试从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"'.

You haven't told the test task to use TestNG: 您还没有告诉测试任务使用TestNG:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM