Я только что интегрировал покрытие кода Jacoco для теста Junit и пользовательского интерфейса в моем проекте Android Studio. < /p>
Я добавил следующие шаги: < /p>
В моем приложении level build.gradle file: < /p>
Я только что интегрировал покрытие кода Jacoco для теста Junit и пользовательского интерфейса в моем проекте Android Studio. < /p> Я добавил следующие шаги: < /p> В моем приложении level build.gradle file: < /p> [code]apply plugin: 'jacoco' < /code> , а затем добавлено ниже кода внутри Android {} < /p> debug { testCoverageEnabled = true enableAndroidTestCoverage = true enableUnitTestCoverage = true } < /code> , а затем добавлено ниже кода: < /p> jacoco { toolVersion = "0.8.8" }
android { // Iterate over all application variants (e.g., debug, release) applicationVariants.configureEach { variant -> // Extract variant name and capitalize the first letter def variantName = variant.name.capitalize()
// Define task names for unit tests and Android tests def unitTests = "test${variantName}UnitTest" def androidTests = "connected${variantName}AndroidTest"
// Register a JacocoReport task for code coverage analysis tasks.register("Jacoco${variantName}CodeCoverage", JacocoReport) { // Depend on unit tests and Android tests tasks dependsOn(unitTests, androidTests)
// Set task grouping and description group = "Reporting" description = "Execute UI and unit tests, generate and combine Jacoco coverage report"
// Configure reports to generate both XML and HTML formats reports { xml.required = true xml.outputLocation = layout.buildDirectory.file("jacoco/xml/${variantName}Coverage.xml")
// Set source directories to the main source directory sourceDirectories.setFrom(layout.projectDirectory.dir("src/main"))
// Set class directories to compiled Java and Kotlin classes, excluding specified exclusions classDirectories.setFrom(files( fileTree(dir: layout.buildDirectory.dir("intermediates/javac/")) { exclude "**/R.class", "**/R\$*.class", "**/BuildConfig.*", "**/Manifest*.*", "**/*Test*.*" }, fileTree(dir: layout.buildDirectory.dir("tmp/kotlin-classes/")) { exclude "**/R.class", "**/R\$*.class", "**/BuildConfig.*", "**/Manifest*.*", "**/*Test*.*" } ))
// Collect execution data from .exec and .ec files generated during test execution executionData.setFrom(files( fileTree(dir: layout.buildDirectory) { include "**/*.exec", "**/*.ec" } )) } } } [/code] Но все же отчет о покрытии кода, не сгенерированный в моей студии Android, любые предложения или направляйте меня здесь! Спасибо заранее!