代码之家  ›  专栏  ›  技术社区  ›  PHPirate

如何将Kotlin源的测试报告上传到工作服?

  •  3
  • PHPirate  · 技术社区  · 7 年前

    我可以在本地和Travis上生成Jacoco测试报告,但当Travis尝试提交到Coveralls时,它会失败并显示消息

    > Task :coveralls
    No source file found on the project: "kotlin-template-project"
    With coverage file: /home/travis/build/myname/myreponame/build/reports/jacoco/test/jacocoTestReport.xml
    

    implementation 它显示了它在哪里抛出这个消息,它告诉我(我想)找到了jacoco报告文件,但没有找到coverall显然需要的源文件。

    因此,我尝试以所有这些方式将coveralls任务指向源文件:

    coveralls {
        sourceDirs += allprojects.sourceSets.main.allSource.srcDirs.flatten()
        sourceDirs += files(sourceSets.main.kotlin.srcDirs).files.absolutePath
        project.extensions.coveralls.sourceDirs += project.sourceSets.main.kotlin.srcDirs
        sourceDirs += ['src/main/kotlin']
        jacocoReportPath = 'build/reports/jacoco/test/jacocoTestReport.xml'
        sourceDirs += ['src/test/kotlin']
        sourceDirs += ["${projectDir}/src/main/kotlin"]
    }
    

    sourceSets project.sourceSets.main jacocoTestReport

    项目设置

    build.gradle

    plugins {
    
        id 'org.jetbrains.kotlin.jvm' version '1.2.50'
        id 'java' // Required by at least JUnit.
    
        // Test coverage
        id 'jacoco'
    
        // Upload jacoco coverage reports to coveralls
        id 'com.github.kt3k.coveralls'  version '2.8.2'
    }
    
    dependencies {
        compile 'org.jetbrains.kotlin:kotlin-stdlib-jdk8'
    
        // JUnit 5
        testImplementation 'org.junit.jupiter:junit-jupiter-api:5.2.0'
        testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.2.0'
        testRuntime 'org.junit.platform:junit-platform-console:1.2.0'
    
        // Kotlintest
        testCompile 'io.kotlintest:kotlintest-core:3.1.6'
        testCompile 'io.kotlintest:kotlintest-assertions:3.1.6'
        testCompile 'io.kotlintest:kotlintest-runner-junit5:3.1.6'
    
        // Spek
        testCompile 'org.jetbrains.spek:spek-api:1.1.5'
        testRuntime 'org.jetbrains.spek:spek-junit-platform-engine:1.1.5'
    }
    
    repositories {
        mavenCentral()
        mavenLocal()
        jcenter()
    }
    
    test {
        // Enable JUnit 5 (Gradle 4.6+).
        useJUnitPlatform()
    
        // Always run tests, even when nothing changed.
        dependsOn 'cleanTest'
    
        // Show test results.
        testLogging {
            events "passed", "skipped", "failed"
        }
    }
    
    // Test coverage reporting
    jacocoTestReport {
        // Enable xml for coveralls.
        reports {
            html.enabled = true
            xml.enabled = true
            xml.setDestination(file("${buildDir}/reports/jacoco/test/jacocoTestReport.xml"))
        }
    }
    
    coveralls {
        sourceDirs += ['src/main/kotlin']
        jacocoReportPath = 'build/reports/jacoco/test/jacocoTestReport.xml'
    }
    

    1 回复  |  直到 7 年前
        1
  •  2
  •   PHPirate    7 年前

    工作服不支持Kotlin,例如,请参见问题中提到的此开放ISSE(在问题中,还提到了此处提供的解决方案不起作用): https://github.com/kt3k/coveralls-gradle-plugin/issues/77

    Codecov.io Marketplace 添加到您的 .travis.yml

    after_success:
      - bash <(curl -s https://codecov.io/bash)
    

    https://codecov.io/gh/githubaccountname/reponame

    推荐文章