Skip to content

test: verify login redirection on HTTP 429 using Robolectric#20361

Open
largeblueberry wants to merge 1 commit intoankidroid:mainfrom
largeblueberry:test/onReceivedHttpError_2
Open

test: verify login redirection on HTTP 429 using Robolectric#20361
largeblueberry wants to merge 1 commit intoankidroid:mainfrom
largeblueberry:test/onReceivedHttpError_2

Conversation

@largeblueberry
Copy link
Contributor

Purpose / Description

This pr is test for user is not redirected to login/signup if they are logged in to AnkiWeb

Fixes

None

Approach

Structure Refactoring for Testability:

  • Changed 'object' to ‘internal inner class’ to access the webclient properties. Because it can only be used in same module and use Activity’s properties

Test code strategy:

  1. Robolectric and Lifecycle management: Injected the spyWebClient before calling start() and resume().
  2. Partial Mocking: Used Mockito Spy to control  isLoggedInToAnkiWeb
  3. assert expected url is equal to last url

Test isolation:

Used the saveControllerForCleanup function in the RobolectricTest file to prevent the previous test from being transferred to the next test.

How Has This Been Tested?

  • Command: .\gradlew :AnkiDroid:testPlayDebugUnitTest --tests "com.ichi2.anki.SharedDecksActivityTest”
  • Result: BUILD SUCCESSFUL

Learning (optional, can help others)

  • Test code should clearly define what it is I want to test and separate everything else from it.
    • Leave the rest outside the test boundary as Mocks or spies, and focus only on the logic you want to test.
    • If the behavior of an external object such as webclient is required, use a spy instead of a mock to make it perform the same behavior as a real object, and intercept it by manipulating the values in the middle.
    • To prevent previous tests from affecting the next test, clean up after each test.
  • Learn how to use RobolectricTest
  • How to Refactor into a Testable Structure
    • Use the internal and @VisibleForTesting annotations to specify that object and private objects have been changed to be used in the same module for testing purposes.

Checklist

Please, go through these checks before submitting the PR.

  • You have a descriptive commit message with a short title (first line, max 50 chars).
  • You have commented your code, particularly in hard-to-understand areas
  • You have performed a self-review of your own code
  • UI changes: include screenshots of all affected screens (in particular showing any new or changed strings)
  • UI Changes: You have tested your change using the Google Accessibility Scanner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant