在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):Kotlin/kotlinx-kover开源软件地址(OpenSource Url):https://github.com/Kotlin/kotlinx-kover开源编程语言(OpenSource Language):Kotlin 100.0%开源软件介绍(OpenSource Introduction):Kotlinx-KoverKover - Gradle plugin for Kotlin code coverage agents: IntelliJ and JaCoCo. Minimal supported Table of contentsFeatures
QuickstartApply plugin to a single-project buildApplying plugins with the plugins DSLIn top-level build file: Kotlinplugins {
id("org.jetbrains.kotlinx.kover") version "0.5.0"
} Groovyplugins {
id 'org.jetbrains.kotlinx.kover' version '0.5.0'
} Legacy Plugin Application: applying plugins with the buildscript blockIn top-level build file: Kotlinbuildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.jetbrains.kotlinx:kover:0.5.0")
}
}
apply(plugin = "kover") Groovybuildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'org.jetbrains.kotlinx:kover:0.5.0'
}
}
apply plugin: 'kover' Apply plugin to a multi-project buildTo apply the plugin to all Gradle projects, you only need to apply the plugin to the top-level build file as shown above. Applying the plugin to subprojects if you have already applied it to the root project will cause configuration errors. ConfigurationOnce applied, the Kover plugin can be used out of the box without additional configuration. However, in some cases, custom settings are needed - this can be done by configuring special extensions and tasks. Configuring JVM test taskIf you need to disable or filter instrumentation for a test task, you may configure the Kover extension for it. For example, to configure a standard test task for Kotlin/JVM named Kotlintasks.test {
extensions.configure(kotlinx.kover.api.KoverTaskExtension::class) {
isDisabled = false
binaryReportFile.set(file("$buildDir/custom/result.bin"))
includes = listOf("com.example.*")
excludes = listOf("com.example.subpackage.*")
}
} Groovytasks.test {
kover {
disabled = false
binaryReportFile.set(file("$buildDir/custom/result.bin"))
includes = ['com.example.*']
excludes = ['com.example.subpackage.*']
}
} For other platforms (Android, Kotlin-Multiplatform) the names may differ and you may also have several test tasks, so you first need to determine the name of the required task. Example of configuring test task for build type Kotlinandroid {
// other Android declarations
testOptions {
unitTests.all {
if (it.name == "testDebugUnitTest") {
it.extensions.configure(kotlinx.kover.api.KoverTaskExtension::class) {
isDisabled = false
binaryReportFile.set(file("$buildDir/custom/debug-report.bin"))
includes = listOf("com.example.*")
excludes = listOf("com.example.subpackage.*")
}
}
}
}
} Groovyandroid {
// other Android declarations
testOptions {
unitTests.all {
if (name == "testDebugUnitTest") {
kover {
disabled = false
binaryReportFile.set(file("$buildDir/custom/debug-report.bin"))
includes = ['com.example.*']
excludes = ['com.example.subpackage.*']
}
}
}
}
} Configuring merged reportsMerged reports combine classpath and coverage stats from the project in which the plugin is applied and all of its subprojects. If you need to change the name of the XML report file or HTML directory, you may configure the corresponding tasks in the project in which the plugin is applied (usually this is the root project): Kotlintasks.koverMergedHtmlReport {
isEnabled = true // false to disable report generation
htmlReportDir.set(layout.buildDirectory.dir("my-merged-report/html-result"))
includes = listOf("com.example.*") // inclusion rules for classes
excludes = listOf("com.example.subpackage.*") // exclusion rules for classes
}
tasks.koverMergedXmlReport {
isEnabled = true // false to disable report generation
xmlReportFile.set(layout.buildDirectory.file("my-merged-report/result.xml"))
includes = listOf("com.example.*") // inclusion rules for classes
excludes = listOf("com.example.subpackage.*") // exclusion rules for classes
} Groovytasks.koverMergedHtmlReport {
enabled = true // false to disable report generation
htmlReportDir.set(layout.buildDirectory.dir("my-merged-report/html-result"))
includes = ['com.example.*'] // inclusion rules for classes
excludes = ['com.example.subpackage.*'] // exclusion rules for classes
}
tasks.koverMergedXmlReport {
enabled = true // false to disable report generation
xmlReportFile.set(layout.buildDirectory.file("my-merged-report/result.xml"))
includes = ['com.example.*'] // inclusion rules for classes
excludes = ['com.example.subpackage.*'] // exclusion rules for classes
} Configuring project reportsIf you need to change the name of the XML report file or HTML directory for a specific project, you may configure the corresponding tasks in this project: Kotlintasks.koverHtmlReport {
isEnabled = true // false to disable report generation
htmlReportDir.set(layout.buildDirectory.dir("my-project-report/html-result"))
includes = listOf("com.example.*") // inclusion rules for classes
excludes = listOf("com.example.subpackage.*") // exclusion rules for classes
}
tasks.koverXmlReport {
isEnabled = true // false to disable report generation
xmlReportFile.set(layout.buildDirectory.file("my-project-report/result.xml"))
includes = listOf("com.example.*") // inclusion rules for classes
excludes = listOf("com.example.subpackage.*") // exclusion rules for classes
} Groovytasks.koverHtmlReport {
enabled = true // false to disable report generation
htmlReportDir.set(layout.buildDirectory.dir("my-project-report/html-result"))
includes = ['com.example.*'] // inclusion rules for classes
excludes = ['com.example.subpackage.*'] // exclusion rules for classes
}
tasks.koverXmlReport {
enabled = true // false to disable report generation
xmlReportFile.set(layout.buildDirectory.file("my-project-report/result.xml"))
includes = ['com.example.*'] // inclusion rules for classes
excludes = ['com.example.subpackage.*'] // exclusion rules for classes
} By default, for tasks In this case, then running tasks You may collect all project reports into one directory using the Kotlintasks.koverCollectReports {
outputDir.set(layout.buildDirectory.dir("all-projects-reports") )
} Groovytasks.koverCollectReports {
outputDir.set(layout.buildDirectory.dir("all-projects-reports") )
} Configuring entire pluginIn the project in which the plugin is applied, you can configure the following properties: Kotlinkover {
isDisabled = false // true to disable instrumentation of all test tasks in all projects
coverageEngine.set(kotlinx.kover.api.CoverageEngine.INTELLIJ) // change instrumentation agent and reporter
intellijEngineVersion.set("1.0.656") // change version of IntelliJ agent and reporter
jacocoEngineVersion.set("0.8.7") // change version of JaCoCo agent and reporter
generateReportOnCheck = true // false to do not execute `koverMergedReport` task before `check` task
disabledProjects = setOf() // setOf("project-name") or setOf(":project-name") to disable coverage for project with path `:project-name` (`:` for the root project)
instrumentAndroidPackage = false // true to instrument packages `android.*` and `com.android.*`
runAllTestsForProjectTask = false // true to run all tests in all projects if `koverHtmlReport`, `koverXmlReport`, `koverReport`, `koverVerify` or `check` tasks executed on some project
} Groovykover {
disabled = false // true to disable instrumentation of all test tasks in all projects
coverageEngine.set(kotlinx.kover.api.CoverageEngine.INTELLIJ) // change instrumentation agent and reporter
intellijEngineVersion.set('1.0.656') // change version of IntelliJ agent and reporter
jacocoEngineVersion.set('0.8.7') // change version of JaCoCo agent and reporter
generateReportOnCheck = true // false to do not execute `koverMergedReport` task before `check` task
disabledProjects = [] // ["project-name"] or [":project-name"] to disable coverage for project with path `:project-name` (`:` for the root project)
instrumentAndroidPackage = false // true to instrument packages `android.*` and `com.android.*`
runAllTestsForProjectTask = false // true to run all tests in all projects if `koverHtmlReport`, `koverXmlReport`, `koverReport`, `koverVerify` or `check` tasks executed on some project
} VerificationYou may specify one or more rules that check the values of the code coverage counters. Validation rules work for both types of agents. The plugin currently only supports line counter values. To add a rule to check coverage of the code of all projects, you need to add configuration to the project in which the plugin is applied (usually this is the root project): Kotlintasks.koverMergedVerify {
includes = listOf("com.example.*") // inclusion rules for classes
excludes = listOf("com.example.subpackage.*") // exclusion rules for classes
rule {
name = "Minimum number of lines covered"
bound {
minValue = 100000
valueType = kotlinx.kover.api.VerificationValueType.COVERED_LINES_COUNT
}
}
rule {
// rule without a custom name
bound {
minValue = 1
maxValue = 1000
valueType = kotlinx.kover.api.VerificationValueType.MISSED_LINES_COUNT
}
}
rule {
name = "Minimal line coverage rate in percent"
bound {
minValue = 50
// valueType is kotlinx.kover.api.VerificationValueType.COVERED_LINES_PERCENTAGE by default
}
}
} Groovytasks.koverMergedVerify {
includes = ['com.example.*'] // inclusion rules for classes
excludes = ['com.example.subpackage.*'] // exclusion rules for classes
rule {
name = "Minimum number of lines covered"
bound {
minValue = 100000
valueType = 'COVERED_LINES_COUNT'
}
}
rule {
// rule without a custom name
bound {
minValue = 1
maxValue = 1000
valueType = 'MISSED_LINES_COUNT'
}
}
rule {
name = "Minimal line coverage rate in percent"
bound {
minValue = 50
// valueType is 'COVERED_LINES_PERCENTAGE' by default
}
}
} To add rules for code coverage checks for the code of one specific project, you need to add a configuration to this project: Kotlintasks.koverVerify {
includes = listOf("com.example.*") // inclusion rules for classes
excludes = listOf("com.example.subpackage.*") // exclusion rules for classes
rule {
name = "Minimal line coverage rate in percent"
bound {
minValue = 75
}
}
} Groovytasks.koverVerify {
includes = ['com.example.*'] // inclusion rules for classes
excludes = ['com.example.subpackage.*'] // exclusion rules for classes
rule {
name = "Minimal line coverage rate in percent"
bound {
minValue = 75
}
}
} By default, for the task In this case, if verification rules are added, then running tasks TasksThe plugin, when applied, automatically creates tasks for the project in which it is applied (usually this is the root project):
Tasks that are created for all projects:
Implicit plugin dependenciesWhile the plugin is being applied, the artifacts of the JaCoCo or IntelliJ toolkit are dynamically loaded. They are downloaded from the For the plugin to work correctly, you need to make sure that the Kotlinrepositories {
mavenCentral()
} Groovyrepositories {
mavenCentral()
} |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论