ankidroid / Anki-Android

AnkiDroid: Anki flashcards on Android. Your secret trick to achieve superhuman information retention.
GNU General Public License v3.0
8.71k stars 2.24k forks source link

CI: `common` module: tests don't run #16618

Open david-allison opened 5 months ago

david-allison commented 5 months ago

Unit tests for the common module don't run in CI


if we have tests and they're just not running that's a "sad miss" because the tests are already there, should log the issue before merge

Originally posted by @mikehardy in https://github.com/ankidroid/Anki-Android/pull/16617#pullrequestreview-2128760104

david-allison commented 5 months ago

Script to check whether tests are running

 ./gradlew jacocoUnitTestReport --dry-run | grep ":common:testPlayDebugUnitTest" 
 ./gradlew testPlayDebugUnitTest --dry-run | grep ":common:testPlayDebugUnitTest"

I looked into this briefly, the following patch solved some, but not all issues

Subject: [PATCH] aa
---
Index: AnkiDroid/build.gradle
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/AnkiDroid/build.gradle b/AnkiDroid/build.gradle
--- a/AnkiDroid/build.gradle    
+++ b/AnkiDroid/build.gradle    
@@ -287,7 +287,6 @@
 }

 apply from: "./robolectricDownloader.gradle"
-apply from: "./jacoco.gradle"
 apply from: "../lint.gradle"

 dependencies {
@@ -423,3 +422,6 @@
     androidTestImplementation libs.kotlin.test.junit
     androidTestImplementation libs.androidx.fragment.testing
 }
+
+// dependencies adds additional tasks
+apply from: "./jacoco.gradle"
\ No newline at end of file
Index: common/build.gradle.kts
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/common/build.gradle.kts b/common/build.gradle.kts
--- a/common/build.gradle.kts   
+++ b/common/build.gradle.kts   
@@ -3,6 +3,7 @@
     alias(libs.plugins.kotlin.android)
 }

+
 android {
     // this cannot conflict with com.ichi2.anki
     // but we can define files in 'com.ichi2.anki' inside 'common'
@@ -26,6 +27,21 @@
             )
         }
     }
+
+    flavorDimensions += "appStore"
+    productFlavors {
+        create("play") {
+            dimension = "appStore"
+        }
+        create("amazon") {
+            dimension = "appStore"
+        }
+        // A 'full' build has no restrictions on storage/camera. Distributed on GitHub/F-Droid
+        create("full") {
+            dimension = "appStore"
+        }
+    }
+
     compileOptions {
         sourceCompatibility = JavaVersion.VERSION_1_8
         targetCompatibility = JavaVersion.VERSION_1_8
Aditya13s commented 5 months ago

Can you explain more about it and what need to be done to solve it.

david-allison commented 5 months ago

Tests aren't run for the common module in CI.

I don't know exactly what's required to fix it, but after it's resolved, tests for common will run in CI under Jacoco

mikehardy commented 5 months ago

note that it is possible to actually add a test (okay: technically build assertion that can fail the build) to make sure tests run! That should be part of the solution

What do I mean? We had a similar problem with emulator testing where zero tests were run sometimes (there was a root cause, which we fixed, but the problem of "silent failure" / "false positive" where we thought tests were running but they weren't was also a problem)

We fixed it like so:

1- a gradle block that is able to determine by looking at test reports if a condition was met (in this case it is that connected tests ran, but in the solution here it could be that some well-known common test ran) 2- making the test task finalize by running that new gradle block

https://github.com/ankidroid/Anki-Android/blob/bd296276fb60a52a4cc6331757abe94427a1ec6b/AnkiDroid/build.gradle#L267-L287

github-actions[bot] commented 2 months ago

Hello 👋, this issue has been opened for more than 3 months with no activity on it. If the issue is still here, please keep in mind that we need community support and help to fix it! Just comment something like still searching for solutions and if you found one, please open a pull request! You have 7 days until this gets closed automatically