Anki-Android
Anki-Android copied to clipboard
Test : Check Snackbar is displayed when the deck is created
Purpose / Description
This test checks whether the toast is shown to user after the deck has been created.
Fix
https://github.com/ankidroid/Anki-Android/blob/1c5a6b3c220d67a75dd4b4d78e1fc8a6cc4b4789/AnkiDroid/src/main/java/com/ichi2/anki/dialogs/CreateDeckDialog.kt#L50
Note : I am currently new towards writing test feel free to pin out or recommend the mistakes or advise while testing.
Few Doubts: @david-allison
-
@NeedsTest("Ensure a toast is shown on a successful action")
I am not sure is this right or wrong. From what i observed creating a deck or renaming a deck we are showing snackbar not toast. I did wrote the unit test (robolectric) for checking whether it showed toast or not but it was giving me null everytime so i later got to know that we are calling snackbar on successful creation. Just likeShadowToast
do we haveShadowSnackbar
which does the work?
For now I have just fixed my old instrument test.
If you annotate
(git blame), you'll see the @NeedsTest
was added in 2022 and you'll see the full context of why we wanted a test
- https://github.com/ankidroid/Anki-Android/pull/12139
Then look at the history of the class to understand how things have changed over time
See from the git history for the file: be85b46869c1fd2b943861fb65e66002721f274c (ShowSnackbarInsteadOfToast)
The intention of the @NeedsTest
is that a user is provided feedback when an action is made.
So test for snackbars, not toasts, and as above, use /test/
rather than /androidTest
Hi Maintainers, I am unsure of how can I check if the Snackbar is displayed or not in Roboelectric? There used to be shadowsnackbar but its now deprecated.
Can you share me what method do we have to test snackbar or any resource link?
This should be in /test/
, not in /androidTest
Closing this as stale to reduce our number of pending PRs. I was going to fix this up, but it needs a rewrite.
Feel free to recreate when this is done