Gradle不执行测试

时间:2019-07-09 21:01:31

标签: java gradle junit junit5

当我运行gradle脚本时,它总是这样做:

> Configure project :
Evaluating root project 'trading-library' using build file 'C:\Users\xxx\Documents\Repositories\Trading_Library\Trading_Library\build.gradle'.
Invalidating in-memory cache of C:\Users\xxx\.gradle\caches\journal-1\file-access.bin
All projects evaluated.
Selected primary task 'cleanTest' from project :
Selected primary task 'test' from project :
Tasks to be executed: [task ':cleanTest', task ':compileJava', task ':processResources', task ':classes', task ':compileTestJava', task ':processTestResources', task ':testClasses', task ':test']
:cleanTest (Thread[Execution worker for ':',5,main]) started.

> Task :cleanTest UP-TO-DATE
Task ':cleanTest' is not up-to-date because:
  Task has not declared any outputs despite executing actions.
:cleanTest (Thread[Execution worker for ':',5,main]) completed. Took 0.002 secs.
:compileJava (Thread[Execution worker for ':',5,main]) started.

> Task :compileJava UP-TO-DATE
Skipping task ':compileJava' as it is up-to-date.
:compileJava (Thread[Execution worker for ':',5,main]) completed. Took 0.029 secs.
:processResources (Thread[Execution worker for ':',5,main]) started.

> Task :processResources NO-SOURCE
Skipping task ':processResources' as it has no source files and no previous output files.
:processResources (Thread[Execution worker for ':',5,main]) completed. Took 0.0 secs.
:classes (Thread[Execution worker for ':',5,main]) started.

> Task :classes UP-TO-DATE
Skipping task ':classes' as it has no actions.
:classes (Thread[Execution worker for ':',5,main]) completed. Took 0.0 secs.
:compileTestJava (Thread[Execution worker for ':',5,main]) started.

> Task :compileTestJava UP-TO-DATE
Skipping task ':compileTestJava' as it is up-to-date.
:compileTestJava (Thread[Execution worker for ':',5,main]) completed. Took 0.032 secs.
:processTestResources (Thread[Execution worker for ':',5,main]) started.

> Task :processTestResources NO-SOURCE
Skipping task ':processTestResources' as it has no source files and no previous output files.
:processTestResources (Thread[Execution worker for ':',5,main]) completed. Took 0.001 secs.
:testClasses (Thread[Execution worker for ':',5,main]) started.

> Task :testClasses UP-TO-DATE
Skipping task ':testClasses' as it has no actions.
:testClasses (Thread[Execution worker for ':',5,main]) completed. Took 0.0 secs.
:test (Thread[Execution worker for ':',5,main]) started.

> Task :test
Task ':test' is not up-to-date because:
  Output property 'binResultsDir' file C:\Users\xxx\Documents\Repositories\Trading_Library\Trading_Library\build\test-results\test\binary has been removed.
  Output property 'binResultsDir' file C:\Users\xxx\Documents\Repositories\Trading_Library\Trading_Library\build\test-results\test\binary\output.bin has been removed.
  Output property 'binResultsDir' file C:\Users\xxx\Documents\Repositories\Trading_Library\Trading_Library\build\test-results\test\binary\output.bin.idx has been removed.
Custom actions are attached to task ':test'.
Finished generating test XML results (0.0 secs) into: C:\Users\xxx\Documents\Repositories\Trading_Library\Trading_Library\build\test-results\test
Generating HTML test report...
Finished generating test html results (0.017 secs) into: C:\Users\xxx\Documents\Repositories\Trading_Library\Trading_Library\build\reports\tests\test
:test (Thread[Execution worker for ':',5,main]) completed. Took 0.367 secs.

这是gradle干净构建后的输出。因此,似乎gradle找不到源,并且gradle也不执行测试。没有生成测试报告,并且测试结果html文件未显示任何已执行的测试。

这是我的gradle文件:

buildscript {
    repositories {
        maven {
            url "${nexusUrl}/content/groups/public/"
            credentials {
                username "$nexusUsername"
                password "$nexusPassword"
            }
        }
    }

    dependencies {
        classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.6"
    }
}


apply plugin: 'maven'
apply plugin: 'java'
apply plugin: "org.sonarqube"
apply plugin: "jacoco"

jar {
    baseName = 'xxx-trading-lib'
    version = '0.0.1-SNAPSHOT'
}

sourceCompatibility = 11
targetCompatibility = 11

repositories {
    maven {
        url "${nexusUrl}/content/groups/public/"
        credentials {
            username "$nexusUsername"
            password "$nexusPassword"
        }
    }
}


group 'de.xxx.libraries'
version '1.0-SNAPSHOT'

sourceCompatibility = 11
targetCompatibility = 11


dependencies {
    compileOnly 'org.projectlombok:lombok:1.18.8'
    annotationProcessor 'org.projectlombok:lombok:1.18.8'

    compile group: 'com.google.guava', name: 'guava', version: '28.0-jre'
    compile group: 'org.joda', name: 'joda-money', version: '1.0.1'
    compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.9'
    compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.25'
    compile group: 'org.slf4j', name: 'slf4j-simple', version: '1.7.25'

    testCompile group: 'org.assertj', name: 'assertj-core', version: '3.12.2'
    testCompile group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.5.0'
    testCompile group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.5.0'


}

task sourcesJar(type: Jar, dependsOn:classes) {
    classifier = 'sources'
    from sourceSets.main.allSource
}

artifacts {
    archives sourcesJar
}

uploadArchives {
    repositories {
        mavenDeployer {

            repository(url: "${nexusUrl}/content/repositories/xxx-trading-release") {
                pom.artifactId = 'xxx-trading-release'
                authentication(userName: nexusUsername, password: nexusPassword)

                pom.version='0.0.1-RELEASE'
                pom.artifactId='xxx-trading-release'
                pom.groupId ='de.xxx.components'

            }


            snapshotRepository(url: "${nexusUrl}/content/repositories/xxx-trading-snapshot") {
                pom.artifactId = 'xxx-trading-snapshot'
                authentication(userName: nexusUsername, password: nexusPassword)

                pom.version='0.0.1-SNAPSHOT'
                pom.artifactId='xxx-trading-snapshot'
                pom.groupId ='de.xxx.components'
            }
        }
    }
}

我还删除了build文件夹,并检查是否将生成类文件,并且工作正常。之后会有新的类文件。有谁知道我在做什么错?我正在使用gradle 5.2.1和Java 11。

编辑:似乎中断了,因为它找不到java.lang.object:

23:10:45.359 [DEBUG] [TestEventLogger] Gradle Test Run :test STARTED
23:10:45.370 [DEBUG] [org.gradle.api.internal.tasks.testing.detection.AbstractTestFrameworkDetector] test-class-scan : failed to scan parent class java/lang/Object, could not find the class file
23:10:45.371 [DEBUG] [org.gradle.api.internal.tasks.testing.detection.AbstractTestFrameworkDetector] test-class-scan : failed to scan parent class java/lang/Object, could not find the class file
23:10:45.371 [DEBUG] [TestEventLogger]
23:10:45.371 [DEBUG] [TestEventLogger] Gradle Test Run :test PASSED 

1 个答案:

答案 0 :(得分:3)

您必须在测试配置中启用JUnit支持。对于JUnit 5,将以下内容添加到gradle构建文件中:

test {
    useJUnitPlatform()
}
相关问题