[Cleanup]: Add Tests to the code (`@NeedsTest`)
[!NOTE] This issue does not need to be assigned to you before you work on it
A number of paths of the code have been identified as requiring automated testing.
Typically this is regression testing: if a bug has been found, then it's useful to have a unit test which would have failed due to the bug.
- Find a usage of
@NeedsTest: https://github.com/ankidroid/Anki-Android/blob/main/AnkiDroid/src/main/java/com/ichi2/annotations/NeedsTest.kt - Post the test(s) that you're handling on this issue, so people don't duplicate work
- Write a unit test (
/test, not/androidTest) - Ensure that re-introducing the bug or issue would break the test
- Submit a Pull Request
please assign this issue to me
Multiple people can work on this issue, please pick a test and let us know!
I suggest clarifying @NeedsTest comments. It is often hard to understand what exactly needs to be tested, and why. For example,
-
@NeedsTest("New User: Accepts permission")inStartupStoragePermissionManager. It is not clear what needs to be tested. A test tests behavior, that's when we do x and expect y. Here the comment doesn't specify y, and does a poor job of describing x. Where do we start?StartupStoragePermissionManagerdoesn't have a definitive entry point. Where do we finish? From reading the code I'm assuming that we expectonRegularStartup()to be called, but I am not sure. -
@NeedsTest("Ensure a toast is shown on a successful action")inCreateDeckDialog. Here buth x and y are specified well enough, but I don't see the reason we need this test. We are not asking to test that creating a deck can succeed, but only that a toast is shown. Assuming there's code likeif (success) showToast(), such a test would be testing Kotlin'sifstatement, which is, I'm assuming, was not what the annotation author wanted to test. -
In a similar fashion,
@NeedsTest("Selecting APKG allows multiple files")inImportFileSelectionFragmentwould be testing Android APIs, not the app. -
@NeedsTest("removing JvmOverloads should fail"). RemovingJvmOverloadsis not behavior of the app or user, but of the programmer. What would the test be like? Can we make a test that would somehow recompile the app, removingJvmOverloads, and then run it in an emulator and verify that it crashes? Suppose this test fails, how does this help us?
I am intrested to look into this issue ,Please assign this issue to me
This issue does not need to be assigned to you before you work on it
Question: are unit tests just preferred over UI tests or is it a hard requirement?
It seems to my Android-newbie eye that a lot of @NeedsTest annotations request a test that validates some UI flow, testable with Espresso. Examples: https://github.com/ankidroid/Anki-Android/blob/main/AnkiDroid/src/main/java/com/ichi2/anki/InitialActivity.kt#L188-L194
Or am I misunderstanding something?
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
Hey :), I've written a test for:
protected open fun editCard(fromGesture: Gesture? = null) {
to cover that inverse animations are being correctly assigned from gestures.
https://github.com/ankidroid/Anki-Android/pull/14337
I'm working on @NeedsTest("constant values are unique").
I'm taking up this https://github.com/ankidroid/Anki-Android/blob/7a4dfd093db8cc794b6f8b5f63e9f0a846b58985/AnkiDroid/src/main/java/com/ichi2/anki/IntroductionActivity.kt#L44
I'll work on this https://github.com/ankidroid/Anki-Android/blob/80487ca9771d309eeee7ad825e37e9582b2a57d7/AnkiDroid/src/main/java/com/ichi2/anki/pages/DeckOptions.kt#L41
Hi, I'm handling the following test:
https://github.com/ankidroid/Anki-Android/blob/0d8a5c44df610a39dfc249db358216a67b5ac0e5/AnkiDroid/src/main/java/com/ichi2/anki/DeckPicker.kt#L238
I work on @NeedsTest("searchView == null -> return early & ensure no snackbar when the screen is opened")
i will work on @NeedsTest("Test functionality which calls this") in file cards.kt
I'm working on this
https://github.com/ankidroid/Anki-Android/blob/60fae6e6f2d1071480d103749fa7715b810ecf46/AnkiDroid/src/main/java/com/ichi2/preferences/NumberRangePreferenceCompat.kt#L189