• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

koral--/jacoco-gradle-testkit-plugin: Gradle plugin for JaCoCo code coverage in ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

koral--/jacoco-gradle-testkit-plugin

开源软件地址(OpenSource Url):

https://github.com/koral--/jacoco-gradle-testkit-plugin

开源编程语言(OpenSource Language):

Kotlin 100.0%

开源软件介绍(OpenSource Introduction):

AppVeyor Travis CI codecov Bitrise

jacoco-gradle-testkit-plugin

Gradle plugin for JaCoCo code coverage in tests using Gradle TestKit.

Motivation

There is no built-it support for code coverage in TestKit. Those tests run in separate JVM and configuration of JaCoCo plugin is not taken into account. See Gradle forum post for more details.

Usage

  • Apply plugin in build.gradle:
plugins {
  id "pl.droidsonroids.jacoco.testkit" version "1.0.8"
}

This will add testkit-gradle.properties system resource.

  • Create gradle.properties file used by GradleRunner and populate it with content from mentioned resource. Sample kotlin code:
class AwesomeTest {

    fun InputStream.toFile(file: File) {
        use { input ->
            file.outputStream().use { input.copyTo(it) }
        }
    }

    fun GradleRunner.withJaCoCo(): GradleRunner {
        javaClass.classLoader.getResourceAsStream("testkit-gradle.properties").toFile(File(projectDir, "gradle.properties"))
        return this
    }

    @get:Rule
    val temporaryFolder = TemporaryProjectFolder()

    @Test
    fun `empty project builds successfuly`() {
        val result = GradleRunner.create()
                .withProjectDir(temporaryFolder.root)
                .withTestKitDir(temporaryFolder.newFolder())
                .withPluginClasspath()
                .withJaCoCo()
                .build()
    }
}

Adding coverage for another task (ex. integrationTest)

By default the plugin configures the test task for any project with Java plugin applied.

To configure the coverage for another task just add something like this:

jacocoTestKit {
    applyTo("intTestRuntimeOnly", tasks.named("integrationTest"))
}

Custom JaCoCo destination file

JaCoCo destination file path reads it from the JacocoTaskExtension so you can change it like this:

tasks.named("test").configure {
    jacoco {
        destinationFile = file('integration.exec')
    }
}

Update from 1.0.5 or older

Starting from plugin version 1.0.6 the minimum supported Gradle version is 4.9




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap