【问题标题】:Gradle does not run unit tests in groovyGradle 不在 groovy 中运行单元测试
【发布时间】:2021-02-15 08:43:21
【问题描述】:

我正在尝试在 groovy 中运行单元测试。测试类本身永远不会被调用。

我的 build.gradle 如下:

apply plugin: 'groovy'

sourceCompatibility = 1.8

repositories {
    mavenCentral()
    maven { url 'https://repo.jenkins-ci.org/releases/' }
}

dependencies {
    implementation 'org.codehaus.groovy:groovy-all:3.0.7'
    testImplementation 'junit:junit:4.12'
    testImplementation "com.lesfurets:jenkins-pipeline-unit:1.3"
}

tasks.withType(Test) { 
  testLogging {
    exceptionFormat "full"
    events "started", "skipped", "passed", "failed"
    showStandardStreams true
  }
}

test {
    useJUnitPlatform()
    testLogging {
        events 'passed', 'skipped', 'failed'
    }

    // delete old test reports
    dependsOn cleanTest

    // don't stop if tests fail
    ignoreFailures = true

    // minimize logging
    testLogging.maxGranularity = 0

    // show stdout from tests
    onOutput { 
        dest, event -> print event.message 
    }

    // show test results
    def results = []
    afterTest { desc, result ->
        println "${desc.className.split("\\.")[-1]}: " +
            "${desc.name}: ${result.resultType}"
    }
    afterSuite { desc, result ->
       if (desc.className) { results << result }
    }

    // show summary
    doLast {
        println "Tests: ${results.sum { it.testCount }}" +
            ", Failures: ${results.sum { it.failedTestCount }}" +
            ", Errors: ${results.sum { it.exceptions.size() }}" + 
            ", Skipped: ${results.sum { it.skippedTestCount }}" 
    }
}

我的文件夹结构如下:

src
   ---main
     ---groovy
       ---<groovy class>
   ---test
      ---groovy
         ---testClass.groovy

当我运行 .gradlew 测试时,我的控制台会显示

Task :test
Tests: null, Failures: null, Errors: null, Skipped: null

BUILD SUCCESSFUL in 5s
4 actionable tasks: 2 executed, 2 up-to-date

尽管我在 groovy 中声明了一个测试类,但测试为空。

有人可以帮忙执行 gradle 测试吗?

【问题讨论】:

    标签: build.gradle jenkins-groovy jenkins-pipeline-unit


    【解决方案1】:

    文件名和类名不同,因为它没有被调用。一旦我给了它正确的名字,它就开始工作了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-06-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多