Skip to content

Commit

Permalink
test: fix studio task recognition for jacoco test tasks
Browse files Browse the repository at this point in the history
if you do the task registration "bare" without assigning to a variable,
Android Studio will recognize your tasks as run targets for UI usage

enable this by refactoring post-definition configuration into the task
definition itself, so no local variable is needed and it's just a "bare"
task creation
  • Loading branch information
mikehardy authored and Arthur-Milchior committed Jan 16, 2025
1 parent 290b43b commit 9c8e6d8
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions AnkiDroid/jacoco.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ else
classDir += "Debug"

// Our merge report task
def testReport = tasks.register('jacocoTestReport', JacocoReport) {
tasks.register('jacocoTestReport', JacocoReport) {
def htmlOutDir = project.layout.buildDirectory.dir("reports/jacoco/$name/html").get().asFile

doLast {
Expand All @@ -120,14 +120,12 @@ def testReport = tasks.register('jacocoTestReport', JacocoReport) {
'**/*.exec',
'**/*.ec'
])
}
testReport.configure {
dependsOn('testPlayDebugUnitTest')
dependsOn("connectedPlay${rootProject.androidTestVariantName}AndroidTest")
}

// A unit-test only report task
def unitTestReport = tasks.register('jacocoUnitTestReport', JacocoReport) {
tasks.register('jacocoUnitTestReport', JacocoReport) {
def htmlOutDir = layout.buildDirectory.dir("reports/jacoco/$name/html").get().asFile

doLast {
Expand All @@ -148,11 +146,11 @@ def unitTestReport = tasks.register('jacocoUnitTestReport', JacocoReport) {
'**/*.exec'

])
dependsOn('testPlayDebugUnitTest')
}
unitTestReport.configure { dependsOn('testPlayDebugUnitTest') }

// A connected android tests only report task
def androidTestReport = tasks.register('jacocoAndroidTestReport', JacocoReport) {
tasks.register('jacocoAndroidTestReport', JacocoReport) {
def htmlOutDir = layout.buildDirectory.dir("reports/jacoco/$name/html").get().asFile

doLast {
Expand All @@ -172,10 +170,9 @@ def androidTestReport = tasks.register('jacocoAndroidTestReport', JacocoReport)
executionData.from = fileTree(dir: project.layout.buildDirectory, includes: [
'**/*.ec'
])
dependsOn("connectedPlay${rootProject.androidTestVariantName}AndroidTest")
}

androidTestReport.configure { dependsOn("connectedPlay${rootProject.androidTestVariantName}AndroidTest") }

// Issue 16640 - some emulators run, but register zero coverage
tasks.register('assertNonzeroAndroidTestCoverage') {
doLast {
Expand Down

0 comments on commit 9c8e6d8

Please sign in to comment.